Skip to content

Commit ae0e126

Browse files
smarterodersky
authored andcommitted
Less eager tvar interpolation: wait until method calls are fully applied
Fix #738
1 parent ecf62cf commit ae0e126

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
563563
val pos = params indexWhere (_.name == param.name)
564564
if (pos < mtpe.paramTypes.length) {
565565
val ptype = mtpe.paramTypes(pos)
566-
if (isFullyDefined(ptype, ForceDegree.none)) return ptype
566+
if (isFullyDefined(ptype, ForceDegree.noBottom)) return ptype
567567
}
568568
case _ =>
569569
}
@@ -1265,7 +1265,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
12651265

12661266
def adapt(tree: Tree, pt: Type, original: untpd.Tree = untpd.EmptyTree)(implicit ctx: Context) = /*>|>*/ track("adapt") /*<|<*/ {
12671267
/*>|>*/ ctx.traceIndented(i"adapting $tree of type ${tree.tpe} to $pt", typr, show = true) /*<|<*/ {
1268-
interpolateUndetVars(tree, if (tree.isDef) tree.symbol else NoSymbol)
1268+
val isMethodCall =
1269+
tree.tpe.widen match {
1270+
case (_: MethodType) | (_: PolyType) if !tree.isDef =>
1271+
true
1272+
case _ =>
1273+
false
1274+
}
1275+
if (!isMethodCall) // Delay tvar interpolation in method calls until they're fully applied
1276+
interpolateUndetVars(tree, if (tree.isDef) tree.symbol else NoSymbol)
1277+
12691278
tree.overwriteType(tree.tpe.simplified)
12701279
adaptInterpolated(tree, pt, original)
12711280
}

tests/pos/tparam_inf.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
def foo1[T](x: T)(implicit ev: T): Nothing = ???
3+
def foo2[T](x: T)(implicit ev: T): T = ???
4+
5+
def test: Unit = {
6+
implicit val ii: Int = 42
7+
8+
foo1(10)
9+
foo2(10)
10+
}
11+
}
12+

0 commit comments

Comments
 (0)