Skip to content

Commit 1ceafdf

Browse files
committed
Improve expected types for dependent functions
1 parent 2f4a3d4 commit 1ceafdf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,12 +1146,15 @@ class Typer extends Namer
11461146
// if expected result type is a wildcard, approximate from above.
11471147
// this can type the greatest set of admissible closures.
11481148
(pt1.argTypesLo.init, typeTree(interpolateWildcards(pt1.argTypesHi.last)))
1149-
case SAMType(sam @ MethodTpe(_, formals, restpe)) =>
1149+
case RefinedType(parent, nme.apply, mt @ MethodTpe(_, formals, restpe))
1150+
if defn.isNonRefinedFunction(parent) && formals.length == defaultArity =>
1151+
(formals, untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef))))
1152+
case SAMType(mt @ MethodTpe(_, formals, restpe)) =>
11501153
(formals,
1151-
if sam.isResultDependent then
1152-
untpd.DependentTypeTree(syms => restpe.substParams(sam, syms.map(_.termRef)))
1153-
else
1154-
typeTree(restpe))
1154+
if (mt.isResultDependent)
1155+
untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef)))
1156+
else
1157+
typeTree(restpe))
11551158
case _ =>
11561159
(List.tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree())
11571160
}

0 commit comments

Comments
 (0)