Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 634d153

Browse files
authoredNov 29, 2017
Merge pull request #3571 from dotty-staging/fix-function-inference
Better function return type inference
2 parents e98ee92 + ddd986b commit 634d153

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
697697
case _: WildcardType => untpd.TypeTree()
698698
case _ => untpd.TypeTree(tp)
699699
}
700-
pt match {
700+
pt.stripTypeVar match {
701701
case _ if defn.isNonDepFunctionType(pt) =>
702702
// if expected parameter type(s) are wildcards, approximate from below.
703703
// if expected result type is a wildcard, approximate from above.
@@ -711,6 +711,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
711711
untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef)))
712712
else
713713
typeTree(restpe))
714+
case tp: TypeParamRef =>
715+
decomposeProtoFunction(ctx.typerState.constraint.entry(tp).bounds.hi, defaultArity)
714716
case _ =>
715717
(List.tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree())
716718
}

‎tests/pos/functions1.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ object Functions {
3333
val z: Spore[String, String] = x => x + x
3434
val z2: Spore2[String, String] = x => x + x
3535
}
36+
37+
object retType {
38+
val a: List[() => 4] = List(() => 4)
39+
40+
class Inv[T]
41+
val b: List[() => Inv[Int]] = List(() => new Inv)
42+
}
3643
}

0 commit comments

Comments
 (0)
Please sign in to comment.