@@ -639,25 +639,33 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
639
639
checkLegalValue(tree2, pt)
640
640
tree2
641
641
642
- def isLocalExtensionMethodRef : Boolean = rawType match
643
- case rawType : TermRef =>
644
- rawType.denot.hasAltWith(_.symbol.is(ExtensionMethod ))
645
- && ! pt.isExtensionApplyProto
646
- && {
642
+ // extensionParam
643
+ def leadParamOf (m : SymDenotation ): Symbol =
644
+ def leadParam (paramss : List [List [Symbol ]]): Symbol = paramss match
645
+ case (param :: _) :: paramss if param.isType => leadParam(paramss)
646
+ case _ :: (param :: Nil ) :: _ if m.name.isRightAssocOperatorName => param
647
+ case (param :: Nil ) :: _ => param
648
+ case _ => NoSymbol
649
+ leadParam(m.rawParamss)
650
+
651
+ val localExtensionSelection : untpd.Tree =
652
+ var select : untpd.Tree = EmptyTree
653
+ if ctx.mode.is(Mode .InExtensionMethod ) then
654
+ rawType match
655
+ case rawType : TermRef
656
+ if rawType.denot.hasAltWith(_.symbol.is(ExtensionMethod )) && ! pt.isExtensionApplyProto =>
647
657
val xmethod = ctx.owner.enclosingExtensionMethod
648
- rawType.denot.hasAltWith { alt =>
649
- alt.symbol.is(ExtensionMethod )
650
- && alt.symbol.extensionParam.span == xmethod.extensionParam.span
651
- }
652
- }
653
- case _ =>
654
- false
658
+ val xparam = leadParamOf(xmethod)
659
+ if rawType.denot.hasAltWith: alt =>
660
+ alt.symbol.is(ExtensionMethod )
661
+ && alt.symbol.extensionParam.span == xparam.span // forces alt.symbol (which might be xmethod)
662
+ then
663
+ select = untpd.cpy.Select (tree)(untpd.ref(xparam), name)
664
+ case _ =>
665
+ select
655
666
656
- if ctx.mode.is(Mode .InExtensionMethod ) && isLocalExtensionMethodRef then
657
- val xmethod = ctx.owner.enclosingExtensionMethod
658
- val qualifier = untpd.ref(xmethod.extensionParam.termRef)
659
- val selection = untpd.cpy.Select (tree)(qualifier, name)
660
- typed(selection, pt)
667
+ if ! localExtensionSelection.isEmpty then
668
+ typed(localExtensionSelection, pt)
661
669
else if rawType.exists then
662
670
val ref = setType(ensureAccessible(rawType, superAccess = false , tree.srcPos))
663
671
if ref.symbol.name != name then
0 commit comments