@@ -1098,7 +1098,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1098
1098
case Apply (fn, _) if fn.symbol.is(ExtensionMethod ) =>
1099
1099
def toSetter (fn : Tree ): untpd.Tree = fn match
1100
1100
case fn @ Ident (name : TermName ) =>
1101
- untpd.cpy.Ident (fn)(name.setterName)
1101
+ // We need to make sure that the prefix of this extension getter is
1102
+ // retained when we transform it into a setter. Otherwise, we could
1103
+ // end up resolving an unrelated setter from another extension. We
1104
+ // transform the `Ident` into a `Select` to ensure that the prefix
1105
+ // is retained with a `TypedSplice` (see `case Select` bellow).
1106
+ // See tests/pos/i18713.scala for an example.
1107
+ (fn.tpe match
1108
+ case TermRef (qual : TermRef , _) =>
1109
+ toSetter(ref(qual).select(fn.symbol).withSpan(fn.span))
1110
+ case TermRef (qual : ThisType , _) =>
1111
+ toSetter(This (qual.cls).select(fn.symbol).withSpan(fn.span))
1112
+ case TermRef (NoPrefix , _) =>
1113
+ untpd.cpy.Ident (fn)(name.setterName)
1114
+ ): @ annotation.nowarn // false-positive match exhastivity warning
1102
1115
case fn @ Select (qual, name : TermName ) =>
1103
1116
untpd.cpy.Select (fn)(untpd.TypedSplice (qual), name.setterName)
1104
1117
case fn @ TypeApply (fn1, targs) =>
0 commit comments