@@ -1125,6 +1125,7 @@ class Typer extends Namer
11251125 newTypeVar(apply(bounds.orElse(TypeBounds .empty)).bounds)
11261126 case _ => mapOver(t)
11271127 }
1128+
11281129 val pt1 = pt.stripTypeVar.dealias
11291130 if (pt1 ne pt1.dropDependentRefinement)
11301131 && defn.isContextFunctionType(pt1.nonPrivateMember(nme.apply).info.finalResultType)
@@ -1133,22 +1134,25 @@ class Typer extends Namer
11331134 i """ Implementation restriction: Expected result type $pt1
11341135 |is a curried dependent context function type. Such types are not yet supported. """ ,
11351136 tree.srcPos)
1137+
11361138 pt1 match {
1137- case pt1 if defn.isNonRefinedFunction(pt1) =>
1138- // if expected parameter type(s) are wildcards, approximate from below.
1139- // if expected result type is a wildcard, approximate from above.
1140- // this can type the greatest set of admissible closures.
1141- (pt1.argTypesLo.init, typeTree(interpolateWildcards(pt1.argTypesHi.last)))
1142- case SAMType (sam @ MethodTpe (_, formals, restpe)) =>
1143- (formals,
1144- if (sam.isResultDependent)
1145- untpd.DependentTypeTree (syms => restpe.substParams(sam, syms.map(_.termRef)))
1146- else
1147- typeTree(restpe))
11481139 case tp : TypeParamRef =>
11491140 decomposeProtoFunction(ctx.typerState.constraint.entry(tp).bounds.hi, defaultArity, tree)
1150- case _ =>
1151- (List .tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree ())
1141+ case _ => pt1.findFunctionTypeInUnion match {
1142+ case pt1 if defn.isNonRefinedFunction(pt1) =>
1143+ // if expected parameter type(s) are wildcards, approximate from below.
1144+ // if expected result type is a wildcard, approximate from above.
1145+ // this can type the greatest set of admissible closures.
1146+ (pt1.argTypesLo.init, typeTree(interpolateWildcards(pt1.argTypesHi.last)))
1147+ case SAMType (sam @ MethodTpe (_, formals, restpe)) =>
1148+ (formals,
1149+ if sam.isResultDependent then
1150+ untpd.DependentTypeTree (syms => restpe.substParams(sam, syms.map(_.termRef)))
1151+ else
1152+ typeTree(restpe))
1153+ case _ =>
1154+ (List .tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree ())
1155+ }
11521156 }
11531157 }
11541158
@@ -1399,7 +1403,7 @@ class Typer extends Namer
13991403 if (tree.tpt.isEmpty)
14001404 meth1.tpe.widen match {
14011405 case mt : MethodType =>
1402- pt.stripNull match {
1406+ pt.findFunctionTypeInUnion match {
14031407 case pt @ SAMType (sam)
14041408 if ! defn.isFunctionType(pt) && mt <:< sam =>
14051409 // SAMs of the form C[?] where C is a class cannot be conversion targets.
0 commit comments