@@ -2123,34 +2123,27 @@ trait Applications extends Compatibility {
21232123 else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
21242124
21252125 case pt =>
2126- val compat0 = pt.dealias match
2127- case defn.FunctionNOf (args, resType, _) =>
2128- narrowByTypes(alts, args, resType)
2129- case _ =>
2130- Nil
2131- if (compat0.isEmpty) then
2132- val compat = alts.filterConserve(normalizedCompatible(_, pt, keepConstraint = false ))
2133- if (compat.isEmpty)
2134- /*
2135- * the case should not be moved to the enclosing match
2136- * since SAM type must be considered only if there are no candidates
2137- * For example, the second f should be chosen for the following code:
2138- * def f(x: String): Unit = ???
2139- * def f: java.io.OutputStream = ???
2140- * new java.io.ObjectOutputStream(f)
2141- */
2142- pt match {
2143- case SAMType (mtp, _) =>
2144- narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
2145- case _ =>
2146- // pick any alternatives that are not methods since these might be convertible
2147- // to the expected type, or be used as extension method arguments.
2148- val convertible = alts.filterNot(alt =>
2149- normalize(alt, IgnoredProto (pt)).widenSingleton.isInstanceOf [MethodType ])
2150- if convertible.length == 1 then convertible else compat
2151- }
2152- else compat
2153- else compat0
2126+ val compat = alts.filterConserve(normalizedCompatible(_, pt, keepConstraint = false ))
2127+ if compat.isEmpty then
2128+ /*
2129+ * the case should not be moved to the enclosing match
2130+ * since SAM type must be considered only if there are no candidates
2131+ * For example, the second f should be chosen for the following code:
2132+ * def f(x: String): Unit = ???
2133+ * def f: java.io.OutputStream = ???
2134+ * new java.io.ObjectOutputStream(f)
2135+ */
2136+ pt match {
2137+ case SAMType (mtp, _) =>
2138+ narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
2139+ case _ =>
2140+ // pick any alternatives that are not methods since these might be convertible
2141+ // to the expected type, or be used as extension method arguments.
2142+ val convertible = alts.filterNot(alt =>
2143+ normalize(alt, IgnoredProto (pt)).widenSingleton.isInstanceOf [MethodType ])
2144+ if convertible.length == 1 then convertible else compat
2145+ }
2146+ else compat
21542147 }
21552148
21562149 /** The type of alternative `alt` after instantiating its first parameter
0 commit comments