@@ -1949,16 +1949,27 @@ trait Applications extends Compatibility {
1949
1949
def resolveOverloaded (alts : List [TermRef ], pt : Type )(using Context ): List [TermRef ] =
1950
1950
record(" resolveOverloaded" )
1951
1951
1952
- /** Is `alt` a method or polytype whose result type after the first value parameter
1952
+ /** Is `alt` a method or polytype whose approximated result type after the first value parameter
1953
1953
* section conforms to the expected type `resultType`? If `resultType`
1954
1954
* is a `IgnoredProto`, pick the underlying type instead.
1955
+ *
1956
+ * Using an approximated result type is necessary to avoid false negatives
1957
+ * due to incomplete type inference such as in tests/pos/i21410.scala and tests/pos/i21410b.scala.
1955
1958
*/
1956
1959
def resultConforms (altSym : Symbol , altType : Type , resultType : Type )(using Context ): Boolean =
1957
1960
resultType.revealIgnored match {
1958
1961
case resultType : ValueType =>
1959
1962
altType.widen match {
1960
- case tp : PolyType => resultConforms(altSym, instantiateWithTypeVars(tp), resultType)
1961
- case tp : MethodType => constrainResult(altSym, tp.resultType, resultType)
1963
+ case tp : PolyType => resultConforms(altSym, tp.resultType, resultType)
1964
+ case tp : MethodType =>
1965
+ val wildRes = wildApprox(tp.resultType)
1966
+
1967
+ class ResultApprox extends AvoidWildcardsMap :
1968
+ // Avoid false negatives by approximating to a lower bound
1969
+ variance = - 1
1970
+
1971
+ val approx = ResultApprox ()(wildRes)
1972
+ constrainResult(altSym, approx, resultType)
1962
1973
case _ => true
1963
1974
}
1964
1975
case _ => true
@@ -2304,6 +2315,7 @@ trait Applications extends Compatibility {
2304
2315
if t.exists && alt.symbol.exists then
2305
2316
val (trimmed, skipped) = trimParamss(t.stripPoly, alt.symbol.rawParamss)
2306
2317
val mappedSym = alt.symbol.asTerm.copy(info = t)
2318
+ mappedSym.annotations = alt.symbol.annotations
2307
2319
mappedSym.rawParamss = trimmed
2308
2320
val (pre, totalSkipped) = mappedAltInfo(alt.symbol) match
2309
2321
case Some ((pre, prevSkipped)) =>
0 commit comments