Skip to content

Commit 08df804

Browse files
committed
Merge pull request #863 from dotty-staging/fix/inference-methcall
Fix/inference methcall
2 parents ecf62cf + 875d7da commit 08df804

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ object Inferencing {
141141
if (toTest.isEmpty) acc
142142
else tree match {
143143
case Apply(fn, _) =>
144-
fn.tpe match {
144+
fn.tpe.widen match {
145145
case mtp: MethodType =>
146146
val (occ, nocc) = toTest.partition(tvar => mtp.paramTypes.exists(tvar.occursIn))
147147
occurring(fn, nocc, occ ::: acc)

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

Lines changed: 3 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,8 @@ 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+
if (tree.isDef) interpolateUndetVars(tree, tree.symbol)
1269+
else if (!tree.tpe.widen.isInstanceOf[MethodOrPoly]) interpolateUndetVars(tree, NoSymbol)
12691270
tree.overwriteType(tree.tpe.simplified)
12701271
adaptInterpolated(tree, pt, original)
12711272
}

tests/pos/tparam_inf.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class HasFoo[T] {
2+
val x: Foo[T] = ???
3+
}
4+
class Foo[T] {
5+
def get(x: T): T = x
6+
def get2(x: T): Nothing = ???
7+
8+
def foo1(x: T)(implicit ev: T): Nothing = ???
9+
def foo2(x: T)(implicit ev: T): T = ???
10+
def foo3[Dummy](x: T)(implicit ev: T): Nothing = ???
11+
def foo4[Dummy](x: T)(implicit ev: T): T = ???
12+
}
13+
14+
object Test {
15+
16+
def foo1[T](x: T)(implicit ev: T): Nothing = ???
17+
def foo2[T](x: T)(implicit ev: T): T = ???
18+
19+
def test1: Unit = {
20+
implicit val ii: Int = 42
21+
22+
foo1(10)
23+
foo2(10)
24+
}
25+
26+
def hf[T]: HasFoo[T] = ???
27+
def test2: Unit = {
28+
implicit val ii: Int = 42
29+
30+
hf.x.get(10)
31+
hf.x.get2(10)
32+
33+
hf.x.foo1(10)
34+
hf.x.foo2(10)
35+
hf.x.foo3(10)
36+
hf.x.foo4(10)
37+
}
38+
}

0 commit comments

Comments
 (0)