Skip to content

Commit eedd309

Browse files
Parametrize resolveMapped by the resolution function
1 parent 111b8d0 commit eedd309

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ trait Applications extends Compatibility {
21692169
val alts0 = alts.filterConserve(_.widen.stripPoly.isImplicitMethod)
21702170
if alts0 ne alts then return resolve(alts0)
21712171
else if alts.exists(_.widen.stripPoly.isContextualMethod) then
2172-
return resolveMapped(alts, alt => stripImplicit(alt.widen), pt, srcPos)
2172+
return resolveMapped(alt => stripImplicit(alt.widen))(alts, pt, srcPos)
21732173
case _ =>
21742174

21752175
var found = withoutMode(Mode.ImplicitsEnabled)(resolveOverloaded1(alts, pt, srcPos))
@@ -2405,7 +2405,7 @@ trait Applications extends Compatibility {
24052405
TypeOps.boundsViolations(targs1, tp.paramInfos, _.substParams(tp, _), NoType).isEmpty
24062406
val alts2 = alts1.filter(withinBounds)
24072407
if isDetermined(alts2) then alts2
2408-
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1, srcPos)
2408+
else resolveMapped(_.widen.appliedTo(targs1.tpes))(alts1, pt1, srcPos)
24092409

24102410
case pt =>
24112411
val compat = alts.filterConserve(normalizedCompatible(_, pt, keepConstraint = false))
@@ -2470,11 +2470,11 @@ trait Applications extends Compatibility {
24702470
case pt @ FunProto(_, PolyProto(targs, resType)) =>
24712471
// try to narrow further with snd argument list and following type params
24722472
warnOnPriorityChange(candidates, found):
2473-
resolveMapped(_, skipParamClause(pt.typedArgs().tpes, targs.tpes), resType, srcPos)
2473+
resolveMapped(skipParamClause(pt.typedArgs().tpes, targs.tpes))(_, resType, srcPos)
24742474
case pt @ FunProto(_, resType: FunOrPolyProto) =>
24752475
// try to narrow further with snd argument list
24762476
warnOnPriorityChange(candidates, found):
2477-
resolveMapped(_, skipParamClause(pt.typedArgs().tpes, Nil), resType, srcPos)
2477+
resolveMapped(skipParamClause(pt.typedArgs().tpes, Nil))(_, resType, srcPos)
24782478
case _ =>
24792479
// prefer alternatives that need no eta expansion
24802480
val noCurried = alts.filterConserve(!resultIsMethod(_))
@@ -2523,11 +2523,13 @@ trait Applications extends Compatibility {
25232523
recur(paramss, 0)
25242524
case _ => (Nil, 0)
25252525

2526-
/** Resolve overloading by mapping to a different problem where each alternative's
2527-
* type is mapped with `f`, alternatives with non-existing types or symbols are dropped, and the
2528-
* expected type is `pt`. Map the results back to the original alternatives.
2526+
/** Resolve with `g` by mapping to a different problem where each alternative's type
2527+
* is mapped with `f`, alternatives with non-existing types or symbols are dropped,
2528+
* and the expected type is `pt`. Map the results back to the original alternatives.
25292529
*/
2530-
def resolveMapped(alts: List[TermRef], f: TermRef => Type, pt: Type, srcPos: SrcPos)(using Context): List[TermRef] =
2530+
def resolveMapped
2531+
(f: TermRef => Type, g: (List[TermRef], Type, SrcPos) => Context ?=> List[TermRef] = resolveOverloaded)
2532+
(alts: List[TermRef], pt: Type, srcPos: SrcPos)(using Context): List[TermRef] =
25312533
val reverseMapping = alts.flatMap { alt =>
25322534
val t = f(alt)
25332535
if t.exists && alt.symbol.exists then
@@ -2550,8 +2552,9 @@ trait Applications extends Compatibility {
25502552
}
25512553
val mapped = reverseMapping.map(_._1)
25522554
overload.println(i"resolve mapped: ${mapped.map(_.widen)}%, % with $pt")
2553-
resolveOverloaded(mapped, pt, srcPos)(using ctx.retractMode(Mode.SynthesizeExtMethodReceiver))
2555+
g(mapped, pt, srcPos)(using ctx.retractMode(Mode.SynthesizeExtMethodReceiver))
25542556
.map(reverseMapping.toMap)
2557+
end resolveMapped
25552558

25562559
/** Try to typecheck any arguments in `pt` that are function values missing a
25572560
* parameter type. If the formal parameter types corresponding to a closure argument

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ object ProtoTypes {
375375
* [](args): resultType
376376
*
377377
* @param args The untyped arguments to which the function is applied
378-
* @param resType The expeected result type
378+
* @param resType The expected result type
379379
* @param typer The typer to use for typing the arguments
380380
* @param applyKind The kind of application (regular/using/tupled infix operand)
381381
* @param state The state object to use for tracking the changes to this prototype

0 commit comments

Comments
 (0)