-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3917: Properly desugar Ident
#3925
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 2 commits
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 |
---|---|---|
|
@@ -826,14 +826,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { | |
*/ | ||
def becomes(rhs: Tree)(implicit ctx: Context): Tree = | ||
if (tree.symbol is Method) { | ||
val setr = tree match { | ||
case Ident(_) => | ||
val setter = tree.symbol.setter | ||
assert(setter.exists, tree.symbol.showLocated) | ||
ref(tree.symbol.setter) | ||
case Select(qual, _) => qual.select(tree.symbol.setter) | ||
val setter = tree.symbol.setter | ||
assert(setter.exists, tree.symbol.showLocated) | ||
val qual = tree match { | ||
case id: Ident => desugarIdentPrefix(id) | ||
case Select(qual, _) => qual | ||
} | ||
setr.appliedTo(rhs) | ||
qual.select(setter).appliedTo(rhs) | ||
} | ||
else Assign(tree, rhs) | ||
|
||
|
@@ -1012,5 +1011,21 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { | |
val encoding = ctx.settings.encoding.value | ||
if (file != null && file.exists) new SourceFile(file, Codec(encoding)) else NoSource | ||
} | ||
|
||
/** Desugar identifier into a select node. Return None if not possible */ | ||
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. We don't usually use Option in the compiler, first, because of the allocation overhead, and second, because we usually have sentinel values that signal absence of a proper result. E.g. I see there are quite a lot of uses of |
||
def desugarIdent(tree: Ident)(implicit ctx: Context): Option[Select] = { | ||
val qual = desugarIdentPrefix(tree) | ||
if (qual.isEmpty) None | ||
else Some(qual.select(tree.symbol)) | ||
} | ||
|
||
private def desugarIdentPrefix(tree: Ident)(implicit ctx: Context): Tree = tree.tpe match { | ||
case TermRef(prefix: TermRef, _) => | ||
ref(prefix) | ||
case TermRef(prefix: ThisType, _) => | ||
This(prefix.cls) | ||
case _ => | ||
EmptyTree | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class A { | ||
var a = false | ||
} | ||
|
||
object B { | ||
var b = false | ||
} | ||
|
||
class C { | ||
var c = false | ||
} | ||
|
||
object C extends A { | ||
def test = { | ||
a = true | ||
C.a = true | ||
this.a = true | ||
C.this.a = true | ||
|
||
import B._ | ||
b = true | ||
|
||
val c0 = new C | ||
import c0._ | ||
c = true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not get rid of the
Option
here since the backend expects this signature