@@ -684,25 +684,33 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
684
684
tree.withType(checkedType)
685
685
checkLegalValue(toNotNullTermRef(tree1, pt), pt)
686
686
687
- def isLocalExtensionMethodRef : Boolean = rawType match
688
- case rawType : TermRef =>
689
- rawType.denot.hasAltWith(_.symbol.is(ExtensionMethod ))
690
- && ! pt.isExtensionApplyProto
691
- && {
687
+ // extensionParam
688
+ def leadParamOf (m : SymDenotation ): Symbol =
689
+ def leadParam (paramss : List [List [Symbol ]]): Symbol = paramss match
690
+ case (param :: _) :: paramss if param.isType => leadParam(paramss)
691
+ case _ :: (param :: Nil ) :: _ if m.name.isRightAssocOperatorName => param
692
+ case (param :: Nil ) :: _ => param
693
+ case _ => NoSymbol
694
+ leadParam(m.rawParamss)
695
+
696
+ val localExtensionSelection : untpd.Tree =
697
+ var select : untpd.Tree = EmptyTree
698
+ if ctx.mode.is(Mode .InExtensionMethod ) then
699
+ rawType match
700
+ case rawType : TermRef
701
+ if rawType.denot.hasAltWith(_.symbol.is(ExtensionMethod )) && ! pt.isExtensionApplyProto =>
692
702
val xmethod = ctx.owner.enclosingExtensionMethod
693
- rawType.denot.hasAltWith { alt =>
694
- alt.symbol.is(ExtensionMethod )
695
- && alt.symbol.extensionParam.span == xmethod.extensionParam.span
696
- }
697
- }
698
- case _ =>
699
- false
703
+ val xparam = leadParamOf(xmethod)
704
+ if rawType.denot.hasAltWith: alt =>
705
+ alt.symbol.is(ExtensionMethod )
706
+ && alt.symbol.extensionParam.span == xparam.span // forces alt.symbol (which might be xmethod)
707
+ then
708
+ select = untpd.cpy.Select (tree)(untpd.ref(xparam), name)
709
+ case _ =>
710
+ select
700
711
701
- if ctx.mode.is(Mode .InExtensionMethod ) && isLocalExtensionMethodRef then
702
- val xmethod = ctx.owner.enclosingExtensionMethod
703
- val qualifier = untpd.ref(xmethod.extensionParam.termRef)
704
- val selection = untpd.cpy.Select (tree)(qualifier, name)
705
- typed(selection, pt)
712
+ if ! localExtensionSelection.isEmpty then
713
+ typed(localExtensionSelection, pt)
706
714
else if rawType.exists then
707
715
val ref = setType(ensureAccessible(rawType, superAccess = false , tree.srcPos))
708
716
if ref.symbol.name != name then
0 commit comments