@@ -1290,29 +1290,30 @@ trait Implicits:
12901290 if alt1.isExtension then
12911291 // Fall back: if both results are extension method applications,
12921292 // compare the extension methods instead of their wrappers.
1293- def stripExtension (alt : SearchSuccess ) = methPart(stripApply(alt.tree)).tpe
1294- (stripExtension(alt1), stripExtension(alt2)) match
1295- case (ref1 : TermRef , ref2 : TermRef ) =>
1296- // ref1 and ref2 might refer to type variables owned by
1297- // alt1.tstate and alt2.tstate respectively, to compare the
1298- // alternatives correctly we need a TyperState that includes
1299- // constraints from both sides, see
1300- // tests/*/extension-specificity2.scala for test cases.
1301- val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1302- val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1303- def exploreState (alt : SearchSuccess ): TyperState =
1304- alt.tstate.fresh(committable = false )
1305- val comparisonState =
1306- if constraintsIn1 && constraintsIn2 then
1307- exploreState(alt1).mergeConstraintWith(alt2.tstate)
1308- else if constraintsIn1 then
1309- exploreState(alt1)
1310- else if constraintsIn2 then
1311- exploreState(alt2)
1312- else
1313- ctx.typerState
1314-
1315- diff = inContext(ctx.withTyperState(comparisonState)):
1293+ def stripExtension (alt : SearchSuccess ) =
1294+ methPart(stripApply(alt.tree)).tpe: @ unchecked match { case ref : TermRef => ref }
1295+ val ref1 = stripExtension(alt1)
1296+ val ref2 = stripExtension(alt2)
1297+ // ref1 and ref2 might refer to type variables owned by
1298+ // alt1.tstate and alt2.tstate respectively, to compare the
1299+ // alternatives correctly we need a TyperState that includes
1300+ // constraints from both sides, see
1301+ // tests/*/extension-specificity2.scala for test cases.
1302+ val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1303+ val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1304+ def exploreState (alt : SearchSuccess ): TyperState =
1305+ alt.tstate.fresh(committable = false )
1306+ val comparisonState =
1307+ if constraintsIn1 && constraintsIn2 then
1308+ exploreState(alt1).mergeConstraintWith(alt2.tstate)
1309+ else if constraintsIn1 then
1310+ exploreState(alt1)
1311+ else if constraintsIn2 then
1312+ exploreState(alt2)
1313+ else
1314+ ctx.typerState
1315+
1316+ diff = inContext(ctx.withTyperState(comparisonState)):
13161317 compare(ref1, ref2)
13171318 else // alt1 is a conversion, prefer extension alt2 over it
13181319 diff = - 1
0 commit comments