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