@@ -2123,34 +2123,27 @@ trait Applications extends Compatibility {
2123
2123
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
2124
2124
2125
2125
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
+ pt match
2129
+ case SAMType (mtp, _) =>
2130
+ // If we have a SAM type as expected type, treat it as if the expression was eta-expanded
2131
+ // Note 1: No need to do that for function types, the previous normalizedCompatible test already
2132
+ // handles those.
2133
+ // Note 2: This case should not be moved to the enclosing match
2134
+ // since fSAM types must be considered only if there are no candidates.
2135
+ // For example, the second f should be chosen for the following code:
2136
+ // def f(x: String): Unit = ???
2137
+ // def f: java.io.OutputStream = ???
2138
+ // new java.io.ObjectOutputStream(f)
2139
+ narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
2140
+ case _ =>
2141
+ // pick any alternatives that are not methods since these might be convertible
2142
+ // to the expected type, or be used as extension method arguments.
2143
+ val convertible = alts.filterNot(alt =>
2144
+ normalize(alt, IgnoredProto (pt)).widenSingleton.isInstanceOf [MethodType ])
2145
+ if convertible.length == 1 then convertible else compat
2146
+ else compat
2154
2147
}
2155
2148
2156
2149
/** The type of alternative `alt` after instantiating its first parameter
0 commit comments