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