@@ -1935,11 +1935,19 @@ trait Applications extends Compatibility {
1935
1935
val ptypes = tp.paramInfos
1936
1936
val numParams = ptypes.length
1937
1937
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
1943
1951
case _ =>
1944
1952
numArgs == 0
1945
1953
}
@@ -2080,6 +2088,14 @@ trait Applications extends Compatibility {
2080
2088
}
2081
2089
end resolveOverloaded1
2082
2090
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
+
2083
2099
/** Resolve overloading by mapping to a different problem where each alternative's
2084
2100
* type is mapped with `f`, alternatives with non-existing types are dropped, and the
2085
2101
* expected type is `pt`. Map the results back to the original alternatives.
@@ -2089,13 +2105,7 @@ trait Applications extends Compatibility {
2089
2105
val t = f(alt)
2090
2106
if t.exists then
2091
2107
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)
2099
2109
Some ((TermRef (NoPrefix , mappedSym), alt))
2100
2110
else
2101
2111
None
0 commit comments