@@ -1383,30 +1383,31 @@ trait Implicits:
13831383 if alt1.isExtension then
13841384 // Fall back: if both results are extension method applications,
13851385 // compare the extension methods instead of their wrappers.
1386- def stripExtension (alt : SearchSuccess ) = methPart(stripApply(alt.tree)).tpe
1387- (stripExtension(alt1), stripExtension(alt2)) match
1388- case (ref1 : TermRef , ref2 : TermRef ) =>
1389- // ref1 and ref2 might refer to type variables owned by
1390- // alt1.tstate and alt2.tstate respectively, to compare the
1391- // alternatives correctly we need a TyperState that includes
1392- // constraints from both sides, see
1393- // tests/*/extension-specificity2.scala for test cases.
1394- val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1395- val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1396- def exploreState (alt : SearchSuccess ): TyperState =
1397- alt.tstate.fresh(committable = false )
1398- val comparisonState =
1399- if constraintsIn1 && constraintsIn2 then
1400- exploreState(alt1).mergeConstraintWith(alt2.tstate)
1401- else if constraintsIn1 then
1402- exploreState(alt1)
1403- else if constraintsIn2 then
1404- exploreState(alt2)
1405- else
1406- ctx.typerState
1407-
1408- diff = inContext(searchContext().withTyperState(comparisonState)):
1409- compare(ref1, ref2, preferGeneral = true )
1386+ def stripExtension (alt : SearchSuccess ) =
1387+ methPart(stripApply(alt.tree)).tpe: @ unchecked match { case ref : TermRef => ref }
1388+ val ref1 = stripExtension(alt1)
1389+ val ref2 = stripExtension(alt2)
1390+ // ref1 and ref2 might refer to type variables owned by
1391+ // alt1.tstate and alt2.tstate respectively, to compare the
1392+ // alternatives correctly we need a TyperState that includes
1393+ // constraints from both sides, see
1394+ // tests/*/extension-specificity2.scala for test cases.
1395+ val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1396+ val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1397+ def exploreState (alt : SearchSuccess ): TyperState =
1398+ alt.tstate.fresh(committable = false )
1399+ val comparisonState =
1400+ if constraintsIn1 && constraintsIn2 then
1401+ exploreState(alt1).mergeConstraintWith(alt2.tstate)
1402+ else if constraintsIn1 then
1403+ exploreState(alt1)
1404+ else if constraintsIn2 then
1405+ exploreState(alt2)
1406+ else
1407+ ctx.typerState
1408+
1409+ diff = inContext(searchContext().withTyperState(comparisonState)):
1410+ compare(ref1, ref2, preferGeneral = true )
14101411 else // alt1 is a conversion, prefer extension alt2 over it
14111412 diff = - 1
14121413 if diff < 0 then alt2
0 commit comments