@@ -1935,11 +1935,19 @@ trait Applications extends Compatibility {
19351935 val ptypes = tp.paramInfos
19361936 val numParams = ptypes.length
19371937 def isVarArgs = ptypes.nonEmpty && ptypes.last.isRepeatedParam
1938- def hasDefault = alt.symbol.hasDefaultParams
1939- if (numParams == numArgs) true
1940- else if (numParams < numArgs) isVarArgs
1941- else if (numParams > numArgs + 1 ) hasDefault
1942- else isVarArgs || hasDefault
1938+ def numDefaultParams =
1939+ if alt.symbol.hasDefaultParams then
1940+ trimParamss(tp, alt.symbol.rawParamss) match
1941+ case params :: _ => params.count(_.is(HasDefault ))
1942+ case _ => 0
1943+ else 0
1944+ if numParams < numArgs then isVarArgs
1945+ else if numParams == numArgs then true
1946+ else
1947+ val numNecessaryArgs = numParams - numDefaultParams
1948+ if numNecessaryArgs <= numArgs then true
1949+ else if numNecessaryArgs == numArgs + 1 then isVarArgs
1950+ else false
19431951 case _ =>
19441952 numArgs == 0
19451953 }
@@ -2080,6 +2088,14 @@ trait Applications extends Compatibility {
20802088 }
20812089 end resolveOverloaded1
20822090
2091+ /** The largest suffix of `paramss` that has the same first parameter name as `t` */
2092+ def trimParamss (t : Type , paramss : List [List [Symbol ]])(using Context ): List [List [Symbol ]] = t match
2093+ case MethodType (Nil ) => trimParamss(t.resultType, paramss)
2094+ case t : MethodOrPoly =>
2095+ val firstParamName = t.paramNames.head
2096+ paramss.dropWhile(_.head.name != firstParamName)
2097+ case _ => Nil
2098+
20832099 /** Resolve overloading by mapping to a different problem where each alternative's
20842100 * type is mapped with `f`, alternatives with non-existing types are dropped, and the
20852101 * expected type is `pt`. Map the results back to the original alternatives.
@@ -2089,13 +2105,7 @@ trait Applications extends Compatibility {
20892105 val t = f(alt)
20902106 if t.exists then
20912107 val mappedSym = alt.symbol.asTerm.copy(info = t)
2092- mappedSym.rawParamss = alt.symbol.rawParamss
2093- // we need rawParamss to find parameters with default arguments,
2094- // but we do not need to be precise right now, since this is just a pre-test before
2095- // we look up default getters. If at some point we extract default arguments from the
2096- // parameter symbols themselves, we have to find the right parameter by name, not position.
2097- // That means it's OK to copy parameters wholesale rather than tailoring them to always
2098- // correspond to the type transformation.
2108+ mappedSym.rawParamss = trimParamss(t, alt.symbol.rawParamss)
20992109 Some ((TermRef (NoPrefix , mappedSym), alt))
21002110 else
21012111 None
0 commit comments