Skip to content

Commit

Permalink
Keep qualifier of Ident when selecting setter
Browse files Browse the repository at this point in the history
We already keep the qualifier as a typed splice if the prefix is an
explicit Select.

Fixes #18713
  • Loading branch information
nicolasstucki committed Oct 18, 2023
1 parent 36a9940 commit 5a1ed3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case Apply(fn, _) if fn.symbol.is(ExtensionMethod) =>
def toSetter(fn: Tree): untpd.Tree = fn match
case fn @ Ident(name: TermName) =>
untpd.cpy.Ident(fn)(name.setterName)
fn.tpe match
case TermRef(qual: TermRef, _) =>
toSetter(ref(qual).select(fn.symbol).withSpan(fn.span))
case _ =>
untpd.cpy.Ident(fn)(name.setterName)
case fn @ Select(qual, name: TermName) =>
untpd.cpy.Select(fn)(untpd.TypedSplice(qual), name.setterName)
case fn @ TypeApply(fn1, targs) =>
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i18713.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import language.experimental.relaxedExtensionImports

class A
object AA:
extension (a: A)
def f = ???
def f_=(x: String) = ???

object BB:
extension (b: Long)
def f = ???
def f_=(x: String) = ???

def test(a: A) =
import AA.*
import BB.*
a.f
a.f = "aa"

0 comments on commit 5a1ed3b

Please sign in to comment.