@@ -2115,8 +2115,11 @@ trait Applications extends Compatibility {
2115
2115
/** Resolve overloaded alternative `alts`, given expected type `pt`.
2116
2116
* Two trials: First, without implicits or SAM conversions enabled. Then,
2117
2117
* if the first finds no eligible candidates, with implicits and SAM conversions enabled.
2118
+ * Each trial applies the `resolve` parameter.
2118
2119
*/
2119
- def resolveOverloaded (alts : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] =
2120
+ def resolveOverloaded
2121
+ (resolve : (List [TermRef ], Type , SrcPos ) => Context ?=> List [TermRef ] = resolveOverloaded1)
2122
+ (alts : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] =
2120
2123
record(" resolveOverloaded" )
2121
2124
2122
2125
/** Is `alt` a method or polytype whose result type after the first value parameter
@@ -2154,31 +2157,31 @@ trait Applications extends Compatibility {
2154
2157
case Nil => chosen
2155
2158
case alt2 :: Nil => alt2
2156
2159
case alts2 =>
2157
- resolveOverloaded(alts2, pt, srcPos) match {
2160
+ resolveOverloaded(resolve)( alts2, pt, srcPos) match {
2158
2161
case alt2 :: Nil => alt2
2159
2162
case _ => chosen
2160
2163
}
2161
2164
}
2162
2165
case _ => chosen
2163
2166
}
2164
2167
2165
- def resolve (alts : List [TermRef ]): List [TermRef ] =
2168
+ def resolve1 (alts : List [TermRef ]): List [TermRef ] =
2166
2169
pt match
2167
2170
case pt : FunProto =>
2168
2171
if pt.applyKind == ApplyKind .Using then
2169
2172
val alts0 = alts.filterConserve(_.widen.stripPoly.isImplicitMethod)
2170
- if alts0 ne alts then return resolve (alts0)
2173
+ if alts0 ne alts then return resolve1 (alts0)
2171
2174
else if alts.exists(_.widen.stripPoly.isContextualMethod) then
2172
- return resolveMapped(alt => stripImplicit(alt.widen))(alts, pt, srcPos)
2175
+ return resolveMapped(alt => stripImplicit(alt.widen), resolve )(alts, pt, srcPos)
2173
2176
case _ =>
2174
2177
2175
- var found = withoutMode(Mode .ImplicitsEnabled )(resolveOverloaded1 (alts, pt, srcPos))
2178
+ var found = withoutMode(Mode .ImplicitsEnabled )(resolve (alts, pt, srcPos))
2176
2179
if found.isEmpty && ctx.mode.is(Mode .ImplicitsEnabled ) then
2177
- found = resolveOverloaded1 (alts, pt, srcPos)
2180
+ found = resolve (alts, pt, srcPos)
2178
2181
found match
2179
2182
case alt :: Nil => adaptByResult(alt, alts) :: Nil
2180
2183
case _ => found
2181
- end resolve
2184
+ end resolve1
2182
2185
2183
2186
/** Try an apply method, if
2184
2187
* - the result is applied to value arguments and alternative is not a method, or
@@ -2211,9 +2214,9 @@ trait Applications extends Compatibility {
2211
2214
2212
2215
if (alts.exists(tryApply)) {
2213
2216
val expanded = alts.flatMap(applyMembers)
2214
- resolve (expanded).map(retract)
2217
+ resolve1 (expanded).map(retract)
2215
2218
}
2216
- else resolve (alts)
2219
+ else resolve1 (alts)
2217
2220
end resolveOverloaded
2218
2221
2219
2222
/** This private version of `resolveOverloaded` does the bulk of the work of
@@ -2286,7 +2289,9 @@ trait Applications extends Compatibility {
2286
2289
def narrowByTypes (alts : List [TermRef ], argTypes : List [Type ], resultType : Type ): List [TermRef ] =
2287
2290
alts.filterConserve(isApplicableMethodRef(_, argTypes, resultType, ArgMatch .CompatibleCAP ))
2288
2291
2289
- def narrowByNextParamClause (alts : List [TermRef ], args : List [Tree ], resultType : FunOrPolyProto ): List [TermRef ] =
2292
+ def narrowByNextParamClause
2293
+ (resolve : (List [TermRef ], Type , SrcPos ) => Context ?=> List [TermRef ])
2294
+ (alts : List [TermRef ], args : List [Tree ], resultType : FunOrPolyProto ): List [TermRef ] =
2290
2295
2291
2296
/** The type of alternative `alt` after instantiating its first parameter
2292
2297
* clause with `argTypes`. In addition, if the resulting type is a PolyType
@@ -2311,10 +2316,10 @@ trait Applications extends Compatibility {
2311
2316
resultType match
2312
2317
case PolyProto (targs, resType) =>
2313
2318
// try to narrow further with snd argument list and following type params
2314
- resolveMapped(skipParamClause(targs.tpes))(alts, resType, srcPos)
2319
+ resolveMapped(skipParamClause(targs.tpes), resolve )(alts, resType, srcPos)
2315
2320
case resType =>
2316
2321
// try to narrow further with snd argument list
2317
- resolveMapped(skipParamClause(Nil ))(alts, resType, srcPos)
2322
+ resolveMapped(skipParamClause(Nil ), resolve )(alts, resType, srcPos)
2318
2323
end narrowByNextParamClause
2319
2324
2320
2325
/** Normalization steps before checking arguments:
@@ -2479,7 +2484,7 @@ trait Applications extends Compatibility {
2479
2484
deepPt match
2480
2485
case pt @ FunProto (_, resType : FunOrPolyProto ) =>
2481
2486
warnOnPriorityChange(candidates, found):
2482
- narrowByNextParamClause(_, pt.typedArgs(), resType)
2487
+ narrowByNextParamClause(resolveOverloaded1)( _, pt.typedArgs(), resType)
2483
2488
case _ =>
2484
2489
// prefer alternatives that need no eta expansion
2485
2490
val noCurried = alts.filterConserve(! resultIsMethod(_))
@@ -2528,12 +2533,12 @@ trait Applications extends Compatibility {
2528
2533
recur(paramss, 0 )
2529
2534
case _ => (Nil , 0 )
2530
2535
2531
- /** Resolve with `g ` by mapping to a different problem where each alternative's type
2532
- * is mapped with `f`, alternatives with non-existing types or symbols are dropped,
2536
+ /** ResolveOverloaded using `resolve ` by mapping to a different problem where each alternative's
2537
+ * type is mapped with `f`, alternatives with non-existing types or symbols are dropped,
2533
2538
* and the expected type is `pt`. Map the results back to the original alternatives.
2534
2539
*/
2535
2540
def resolveMapped
2536
- (f : TermRef => Type , g : (List [TermRef ], Type , SrcPos ) => Context ?=> List [TermRef ] = resolveOverloaded )
2541
+ (f : TermRef => Type , resolve : (List [TermRef ], Type , SrcPos ) => Context ?=> List [TermRef ])
2537
2542
(alts : List [TermRef ], pt : Type , srcPos : SrcPos )(using Context ): List [TermRef ] =
2538
2543
val reverseMapping = alts.flatMap { alt =>
2539
2544
val t = f(alt)
@@ -2557,7 +2562,7 @@ trait Applications extends Compatibility {
2557
2562
}
2558
2563
val mapped = reverseMapping.map(_._1)
2559
2564
overload.println(i " resolve mapped: ${mapped.map(_.widen)}%, % with $pt" )
2560
- g (mapped, pt, srcPos)(using ctx.retractMode(Mode .SynthesizeExtMethodReceiver ))
2565
+ resolveOverloaded(resolve) (mapped, pt, srcPos)(using ctx.retractMode(Mode .SynthesizeExtMethodReceiver ))
2561
2566
.map(reverseMapping.toMap)
2562
2567
end resolveMapped
2563
2568
0 commit comments