@@ -2062,31 +2062,35 @@ trait Applications extends Compatibility {
2062
2062
if isDetermined(alts2) then alts2
2063
2063
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
2064
2064
2065
- case defn.FunctionOf (args, resultType, _) =>
2066
- narrowByTypes(alts, args, resultType)
2067
-
2068
2065
case pt =>
2069
- val compat = alts.filterConserve(normalizedCompatible(_, pt, keepConstraint = false ))
2070
- if (compat.isEmpty)
2071
- /*
2072
- * the case should not be moved to the enclosing match
2073
- * since SAM type must be considered only if there are no candidates
2074
- * For example, the second f should be chosen for the following code:
2075
- * def f(x: String): Unit = ???
2076
- * def f: java.io.OutputStream = ???
2077
- * new java.io.ObjectOutputStream(f)
2078
- */
2079
- pt match {
2080
- case SAMType (mtp) =>
2081
- narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
2082
- case _ =>
2083
- // pick any alternatives that are not methods since these might be convertible
2084
- // to the expected type, or be used as extension method arguments.
2085
- val convertible = alts.filterNot(alt =>
2086
- normalize(alt, IgnoredProto (pt)).widenSingleton.isInstanceOf [MethodType ])
2087
- if convertible.length == 1 then convertible else compat
2088
- }
2089
- else compat
2066
+ val compat0 = pt match
2067
+ case defn.FunctionOf (args, resType, _) =>
2068
+ narrowByTypes(alts, args, resType)
2069
+ case _ =>
2070
+ Nil
2071
+ if (compat0.isEmpty) then
2072
+ val compat = alts.filterConserve(normalizedCompatible(_, pt, keepConstraint = false ))
2073
+ if (compat.isEmpty)
2074
+ /*
2075
+ * the case should not be moved to the enclosing match
2076
+ * since SAM type must be considered only if there are no candidates
2077
+ * For example, the second f should be chosen for the following code:
2078
+ * def f(x: String): Unit = ???
2079
+ * def f: java.io.OutputStream = ???
2080
+ * new java.io.ObjectOutputStream(f)
2081
+ */
2082
+ pt match {
2083
+ case SAMType (mtp) =>
2084
+ narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
2085
+ case _ =>
2086
+ // pick any alternatives that are not methods since these might be convertible
2087
+ // to the expected type, or be used as extension method arguments.
2088
+ val convertible = alts.filterNot(alt =>
2089
+ normalize(alt, IgnoredProto (pt)).widenSingleton.isInstanceOf [MethodType ])
2090
+ if convertible.length == 1 then convertible else compat
2091
+ }
2092
+ else compat
2093
+ else compat0
2090
2094
}
2091
2095
2092
2096
/** The type of alternative `alt` after instantiating its first parameter
0 commit comments