-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Keep qualifier of Ident when selecting setter #18714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1119,7 +1119,19 @@ 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) | ||
// We need to make sure that the prefix of this extension getter is | ||
// retained when we transform it into a setter. Otherwise, we could | ||
// end up resoving an unrelated setter from another extension. We | ||
// transform the `Ident` into a `Select` to ensure that the prefix | ||
// is retained with a `TypedSplice` (see `case Select` bellow). | ||
// See tests/pos/i18713.scala for an example. | ||
fn.tpe match | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks non-sensical that on the one hand we can refer to a lhs with a simple ident, but on the other hand the setter needs a full tree expansion. Can you add a comment why that is so? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment |
||
case TermRef(qual: TermRef, _) => | ||
toSetter(ref(qual).select(fn.symbol).withSpan(fn.span)) | ||
case TermRef(qual: ThisType, _) => | ||
toSetter(This(qual.cls).select(fn.symbol).withSpan(fn.span)) | ||
case TermRef(NoPrefix, _) => | ||
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) => | ||
|
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" |
Uh oh!
There was an error while loading. Please reload this page.