@@ -2118,8 +2118,8 @@ trait Applications extends Compatibility {
21182118 * Each trial applies the `resolve` parameter.
21192119 */
21202120 def resolveOverloaded
2121- (resolve : (List [TermRef ], Type , SrcPos ) => Context ?=> List [TermRef ] = resolveOverloaded1)
2122- (alts : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] =
2121+ (resolve : (List [TermRef ], Type ) => Context ?=> List [TermRef ] = resolveOverloaded1)
2122+ (alts : List [TermRef ], pt : Type , srcPos : SrcPos = NoSourcePosition )(using Context ): List [TermRef ] =
21232123 record(" resolveOverloaded" )
21242124
21252125 /** Is `alt` a method or polytype whose result type after the first value parameter
@@ -2172,12 +2172,12 @@ trait Applications extends Compatibility {
21722172 val alts0 = alts.filterConserve(_.widen.stripPoly.isImplicitMethod)
21732173 if alts0 ne alts then return resolve1(alts0)
21742174 else if alts.exists(_.widen.stripPoly.isContextualMethod) then
2175- return resolveMapped(alt => stripImplicit(alt.widen), resolve)(alts, pt, srcPos )
2175+ return resolveMapped(alt => stripImplicit(alt.widen), resolve)(alts, pt)
21762176 case _ =>
21772177
2178- var found = withoutMode(Mode .ImplicitsEnabled )(resolve(alts, pt, srcPos ))
2178+ var found = withoutMode(Mode .ImplicitsEnabled )(resolve(alts, pt))
21792179 if found.isEmpty && ctx.mode.is(Mode .ImplicitsEnabled ) then
2180- found = resolve(alts, pt, srcPos )
2180+ found = resolve(alts, pt)
21812181 found match
21822182 case alt :: Nil => adaptByResult(alt, alts) :: Nil
21832183 case _ => found
@@ -2224,43 +2224,10 @@ trait Applications extends Compatibility {
22242224 * It might be called twice from the public `resolveOverloaded` method, once with
22252225 * implicits and SAM conversions enabled, and once without.
22262226 */
2227- private def resolveOverloaded1 (alts : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] =
2227+ private def resolveOverloaded1 (alts : List [TermRef ], pt : Type )(using Context ): List [TermRef ] =
22282228 trace(i " resolve over $alts%, %, pt = $pt" , typr, show = true ):
22292229 record(s " resolveOverloaded1 " , alts.length)
22302230
2231- val sv = Feature .sourceVersion
2232- val isOldPriorityVersion : Boolean = sv.isAtMost(SourceVersion .`3.7`)
2233- val isWarnPriorityChangeVersion = sv == SourceVersion .`3.7` || sv == SourceVersion .`3.8-migration`
2234-
2235- def warnOnPriorityChange (oldCands : List [TermRef ], newCands : List [TermRef ])(f : List [TermRef ] => List [TermRef ]): List [TermRef ] =
2236- lazy val oldRes = f(oldCands)
2237- val newRes = f(newCands)
2238-
2239- def doWarn (oldChoice : String , newChoice : String ): Unit =
2240- val (change, whichChoice) =
2241- if isOldPriorityVersion
2242- then (" will change" , " Current choice " )
2243- else (" has changed" , " Previous choice" )
2244-
2245- val msg = // using oldCands to list the alternatives as they should be a superset of newCands
2246- em """ Overloading resolution for ${err.expectedTypeStr(pt)} between alternatives
2247- | ${oldCands map (_.info)}%\n %
2248- | $change.
2249- | $whichChoice : $oldChoice
2250- |New choice from Scala 3.7: $newChoice"""
2251-
2252- report.warning(msg, srcPos)
2253- end doWarn
2254-
2255- if isWarnPriorityChangeVersion then (oldRes, newRes) match
2256- case (oldAlt :: Nil , newAlt :: Nil ) if oldAlt != newAlt => doWarn(oldAlt.info.show, newAlt.info.show)
2257- case (oldAlt :: Nil , Nil ) => doWarn(oldAlt.info.show, " none" )
2258- case (Nil , newAlt :: Nil ) => doWarn(" none" , newAlt.info.show)
2259- case _ => // neither scheme has determined an alternative
2260-
2261- if isOldPriorityVersion then oldRes else newRes
2262- end warnOnPriorityChange
2263-
22642231 def isDetermined (alts : List [TermRef ]) = alts.isEmpty || alts.tail.isEmpty
22652232
22662233 /** The shape of given tree as a type; cannot handle named arguments. */
@@ -2290,7 +2257,7 @@ trait Applications extends Compatibility {
22902257 alts.filterConserve(isApplicableMethodRef(_, argTypes, resultType, ArgMatch .CompatibleCAP ))
22912258
22922259 def narrowByNextParamClause
2293- (resolve : (List [TermRef ], Type , SrcPos ) => Context ?=> List [TermRef ])
2260+ (resolve : (List [TermRef ], Type ) => Context ?=> List [TermRef ])
22942261 (alts : List [TermRef ], args : List [Tree ], resultType : FunOrPolyProto ): List [TermRef ] =
22952262
22962263 /** The type of alternative `alt` after instantiating its first parameter
@@ -2316,10 +2283,10 @@ trait Applications extends Compatibility {
23162283 resultType match
23172284 case PolyProto (targs, resType) =>
23182285 // try to narrow further with snd argument list and following type params
2319- resolveMapped(skipParamClause(targs.tpes), resolve)(alts, resType, srcPos )
2286+ resolveMapped(skipParamClause(targs.tpes), resolve)(alts, resType)
23202287 case resType =>
23212288 // try to narrow further with snd argument list
2322- resolveMapped(skipParamClause(Nil ), resolve)(alts, resType, srcPos )
2289+ resolveMapped(skipParamClause(Nil ), resolve)(alts, resType)
23232290 end narrowByNextParamClause
23242291
23252292 /** Normalization steps before checking arguments:
@@ -2381,7 +2348,7 @@ trait Applications extends Compatibility {
23812348 // Note it is important not to capture the outer ctx, for when it is passed to resolveMapped
23822349 // (through narrowByNextParamClause) which retracts the Mode.SynthesizeExtMethodReceiver from the ctx
23832350 // before continuing to `resolveCandidates`.
2384- def resolveCandidates (alts : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] = pt match
2351+ def resolveCandidates (alts : List [TermRef ], pt : Type )(using Context ): List [TermRef ] = pt match
23852352 case pt @ FunProto (args, resultType) =>
23862353 val numArgs = args.length
23872354 def sizeFits (alt : TermRef ): Boolean = alt.widen.stripPoly match {
@@ -2450,7 +2417,7 @@ trait Applications extends Compatibility {
24502417 TypeOps .boundsViolations(targs1, tp.paramInfos, _.substParams(tp, _), NoType ).isEmpty
24512418 val alts2 = alts1.filter(withinBounds)
24522419 if isDetermined(alts2) then alts2
2453- else resolveMapped(_.widen.appliedTo(targs1.tpes), resolveCandidates)(alts1, pt1, srcPos )
2420+ else resolveMapped(_.widen.appliedTo(targs1.tpes), resolveCandidates)(alts1, pt1)
24542421
24552422 case pt =>
24562423 val compat = alts.filterConserve(normalizedCompatible(_, pt, keepConstraint = false ))
@@ -2481,7 +2448,7 @@ trait Applications extends Compatibility {
24812448 case _ => false
24822449
24832450 // Like resolveCandidates, we should not capture the outer ctx parameter.
2484- def resolveOverloaded2 (candidates : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] =
2451+ def resolveOverloaded2 (candidates : List [TermRef ], pt : Type )(using Context ): List [TermRef ] =
24852452 if pt.unusableForInference then
24862453 // `pt` might have become erroneous by typing arguments of FunProtos.
24872454 // If `pt` is erroneous, don't try to go further; report the error in `pt` instead.
@@ -2493,27 +2460,26 @@ trait Applications extends Compatibility {
24932460 val deepPt = pt.deepenProto
24942461 deepPt match
24952462 case pt @ FunProto (_, resType : FunOrPolyProto ) =>
2496- warnOnPriorityChange(candidates, found):
2497- narrowByNextParamClause(resolveOverloaded1)(_, pt.typedArgs(), resType)
2463+ narrowByNextParamClause(resolveOverloaded1)(found, pt.typedArgs(), resType)
24982464 case _ =>
24992465 // prefer alternatives that need no eta expansion
25002466 val noCurried = alts.filterConserve(! resultIsMethod(_))
25012467 val noCurriedCount = noCurried.length
25022468 if noCurriedCount == 1 then
25032469 noCurried
25042470 else if noCurriedCount > 1 && noCurriedCount < alts.length then
2505- resolveOverloaded1(noCurried, pt, srcPos )
2471+ resolveOverloaded1(noCurried, pt)
25062472 else
25072473 // prefer alternatves that match without default parameters
25082474 val noDefaults = alts.filterConserve(! _.symbol.hasDefaultParams)
25092475 val noDefaultsCount = noDefaults.length
25102476 if noDefaultsCount == 1 then
25112477 noDefaults
25122478 else if noDefaultsCount > 1 && noDefaultsCount < alts.length then
2513- resolveOverloaded1(noDefaults, pt, srcPos )
2479+ resolveOverloaded1(noDefaults, pt)
25142480 else if deepPt ne pt then
25152481 // try again with a deeper known expected type
2516- resolveOverloaded1(alts, deepPt, srcPos )
2482+ resolveOverloaded1(alts, deepPt)
25172483 else
25182484 candidates
25192485 end resolveOverloaded2
@@ -2523,9 +2489,9 @@ trait Applications extends Compatibility {
25232489 // but restarting from the 1st argument list.
25242490 // In both cases, considering subsequent argument lists only narrows the set of alternatives
25252491 // (i.e. we do retry from the complete list of alternative mapped onto there next param clause).
2526- val candidates = resolveCandidates(alts, pt, srcPos )
2492+ val candidates = resolveCandidates(alts, pt)
25272493 record(" resolveOverloaded.narrowedApplicable" , candidates.length)
2528- resolveOverloaded2(candidates, pt, srcPos )
2494+ resolveOverloaded2(candidates, pt)
25292495 end resolveOverloaded1
25302496
25312497 /** Is `formal` a product type which is elementwise compatible with `params`? */
@@ -2557,8 +2523,8 @@ trait Applications extends Compatibility {
25572523 * and the expected type is `pt`. Map the results back to the original alternatives.
25582524 */
25592525 def resolveMapped
2560- (f : TermRef => Type , resolve : (List [TermRef ], Type , SrcPos ) => Context ?=> List [TermRef ])
2561- (alts : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] =
2526+ (f : TermRef => Type , resolve : (List [TermRef ], Type ) => Context ?=> List [TermRef ])
2527+ (alts : List [TermRef ], pt : Type )(using Context ): List [TermRef ] =
25622528 val reverseMapping = alts.flatMap { alt =>
25632529 val t = f(alt)
25642530 if t.exists && alt.symbol.exists then
@@ -2581,7 +2547,7 @@ trait Applications extends Compatibility {
25812547 }
25822548 val mapped = reverseMapping.map(_._1)
25832549 overload.println(i " resolve mapped: ${mapped.map(_.widen)}%, % with $pt" )
2584- resolveOverloaded(resolve)(mapped, pt, srcPos )(using ctx.retractMode(Mode .SynthesizeExtMethodReceiver ))
2550+ resolveOverloaded(resolve)(mapped, pt)(using ctx.retractMode(Mode .SynthesizeExtMethodReceiver ))
25852551 .map(reverseMapping.toMap)
25862552 end resolveMapped
25872553
0 commit comments