@@ -1125,19 +1125,6 @@ class Typer extends Namer
1125
1125
newTypeVar(apply(bounds.orElse(TypeBounds .empty)).bounds)
1126
1126
case _ => mapOver(t)
1127
1127
}
1128
- def extractInUnion (t : Type ): Seq [Type ] = t match {
1129
- case t : OrType =>
1130
- extractInUnion(t.tp1) ++ extractInUnion(t.tp2)
1131
- case t : TypeParamRef =>
1132
- extractInUnion(ctx.typerState.constraint.entry(t).bounds.hi)
1133
- case t if defn.isNonRefinedFunction(t) =>
1134
- Seq (t)
1135
- case SAMType (_ : MethodType ) =>
1136
- Seq (t)
1137
- case _ =>
1138
- Nil
1139
- }
1140
- def defaultResult = (List .tabulate(defaultArity)(alwaysWildcardType), untpd.TypeTree ())
1141
1128
1142
1129
val pt1 = pt.stripTypeVar.dealias
1143
1130
if (pt1 ne pt1.dropDependentRefinement)
@@ -1148,11 +1135,7 @@ class Typer extends Namer
1148
1135
|is a curried dependent context function type. Such types are not yet supported. """ ,
1149
1136
tree.srcPos)
1150
1137
1151
- val elems = extractInUnion(pt1)
1152
- if elems.length != 1 then
1153
- // The union type containing multiple function types is ignored
1154
- defaultResult
1155
- else elems.head match {
1138
+ pt1.findFuntionTypeInUnion match {
1156
1139
case pt1 if defn.isNonRefinedFunction(pt1) =>
1157
1140
// if expected parameter type(s) are wildcards, approximate from below.
1158
1141
// if expected result type is a wildcard, approximate from above.
@@ -1165,7 +1148,7 @@ class Typer extends Namer
1165
1148
else
1166
1149
typeTree(restpe))
1167
1150
case _ =>
1168
- defaultResult
1151
+ ( List .tabulate(defaultArity)(alwaysWildcardType), untpd. TypeTree ())
1169
1152
}
1170
1153
}
1171
1154
@@ -1410,22 +1393,14 @@ class Typer extends Namer
1410
1393
}
1411
1394
1412
1395
def typedClosure (tree : untpd.Closure , pt : Type )(using Context ): Tree = {
1413
- def extractInUnion (t : Type ): Seq [Type ] = t match {
1414
- case t : OrType =>
1415
- extractInUnion(t.tp1) ++ extractInUnion(t.tp2)
1416
- case SAMType (_) =>
1417
- Seq (t)
1418
- case _ =>
1419
- Nil
1420
- }
1421
1396
val env1 = tree.env mapconserve (typed(_))
1422
1397
val meth1 = typedUnadapted(tree.meth)
1423
1398
val target =
1424
1399
if (tree.tpt.isEmpty)
1425
1400
meth1.tpe.widen match {
1426
1401
case mt : MethodType =>
1427
- extractInUnion(pt) match {
1428
- case Seq ( pt @ SAMType (sam) )
1402
+ pt.findFuntionTypeInUnion match {
1403
+ case pt @ SAMType (sam)
1429
1404
if ! defn.isFunctionType(pt) && mt <:< sam =>
1430
1405
// SAMs of the form C[?] where C is a class cannot be conversion targets.
1431
1406
// The resulting class `class $anon extends C[?] {...}` would be illegal,
0 commit comments