Skip to content

More type parameters' inference fixes #861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ object Inferencing {
if (toTest.isEmpty) acc
else tree match {
case Apply(fn, _) =>
fn.tpe match {
fn.tpe.widen match {
case mtp: MethodType =>
val (occ, nocc) = toTest.partition(tvar => mtp.paramTypes.exists(tvar.occursIn))
occurring(fn, nocc, occ ::: acc)
Expand Down
13 changes: 11 additions & 2 deletions src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val pos = params indexWhere (_.name == param.name)
if (pos < mtpe.paramTypes.length) {
val ptype = mtpe.paramTypes(pos)
if (isFullyDefined(ptype, ForceDegree.none)) return ptype
if (isFullyDefined(ptype, ForceDegree.noBottom)) return ptype
}
case _ =>
}
Expand Down Expand Up @@ -1265,7 +1265,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit

def adapt(tree: Tree, pt: Type, original: untpd.Tree = untpd.EmptyTree)(implicit ctx: Context) = /*>|>*/ track("adapt") /*<|<*/ {
/*>|>*/ ctx.traceIndented(i"adapting $tree of type ${tree.tpe} to $pt", typr, show = true) /*<|<*/ {
interpolateUndetVars(tree, if (tree.isDef) tree.symbol else NoSymbol)
val isMethodCall =
tree.tpe.widen match {
case (_: MethodType) | (_: PolyType) if !tree.isDef =>
true
case _ =>
false
}
if (!isMethodCall) // Delay tvar interpolation in method calls until they're fully applied
interpolateUndetVars(tree, if (tree.isDef) tree.symbol else NoSymbol)

tree.overwriteType(tree.tpe.simplified)
adaptInterpolated(tree, pt, original)
}
Expand Down
38 changes: 38 additions & 0 deletions tests/pos/tparam_inf.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class HasFoo[T] {
val x: Foo[T] = ???
}
class Foo[T] {
def get(x: T): T = x
def get2(x: T): Nothing = ???

def foo1(x: T)(implicit ev: T): Nothing = ???
def foo2(x: T)(implicit ev: T): T = ???
def foo3[Dummy](x: T)(implicit ev: T): Nothing = ???
def foo4[Dummy](x: T)(implicit ev: T): T = ???
}

object Test {

def foo1[T](x: T)(implicit ev: T): Nothing = ???
def foo2[T](x: T)(implicit ev: T): T = ???

def test1: Unit = {
implicit val ii: Int = 42

foo1(10)
foo2(10)
}

def hf[T]: HasFoo[T] = ???
def test2: Unit = {
implicit val ii: Int = 42

hf.x.get(10)
hf.x.get2(10)

hf.x.foo1(10)
hf.x.foo2(10)
hf.x.foo3(10)
hf.x.foo4(10)
}
}