@@ -1949,16 +1949,27 @@ trait Applications extends Compatibility {
19491949 def resolveOverloaded (alts : List [TermRef ], pt : Type )(using Context ): List [TermRef ] =
19501950 record(" resolveOverloaded" )
19511951
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
19531953 * section conforms to the expected type `resultType`? If `resultType`
19541954 * 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.
19551958 */
19561959 def resultConforms (altSym : Symbol , altType : Type , resultType : Type )(using Context ): Boolean =
19571960 resultType.revealIgnored match {
19581961 case resultType : ValueType =>
19591962 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)
19621973 case _ => true
19631974 }
19641975 case _ => true
@@ -2304,6 +2315,7 @@ trait Applications extends Compatibility {
23042315 if t.exists && alt.symbol.exists then
23052316 val (trimmed, skipped) = trimParamss(t.stripPoly, alt.symbol.rawParamss)
23062317 val mappedSym = alt.symbol.asTerm.copy(info = t)
2318+ mappedSym.annotations = alt.symbol.annotations
23072319 mappedSym.rawParamss = trimmed
23082320 val (pre, totalSkipped) = mappedAltInfo(alt.symbol) match
23092321 case Some ((pre, prevSkipped)) =>
0 commit comments