-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4395: Handle ## when it is an Ident #4474
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
Conversation
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context): Tree = { | ||
if (tree.symbol.isTerm && (defn.Any_## eq tree.symbol.asTerm)) { | ||
val cls = ctx.owner.ownersIterator.find(_.isClass).get.asClass | ||
val rewrite = poundPoundValue(This(cls)) |
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 think what you want is tpd.desugarIdentPrefix
@@ -54,6 +38,16 @@ class InterceptedMethods extends MiniPhase { | |||
else tree | |||
} | |||
|
|||
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context): Tree = { |
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.
Can you factor out the common code between transformIdent
and transformSelect
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.
poundPoundValue
already factors it out. The rest is just slightly different.
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.
What about something like:
private def transformRefTree(tree: RefTree)(implicit ctx: Context): Tree =
if (tree.symbol.isTerm && (defn.Any_## eq tree.symbol)) {
val qual = tree match
case id: Ident => tpd.desugarIdentPrefix(id)
case sel: Select => sel.qual
}
val rewrite = poundPoundValue(qual)
ctx.log(s"$phaseName rewrote $tree to $rewrite")
rewrite
}
else tree
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context) =
transformRefTree(tree)
override def transformSelect(tree: tpd.Select)(implicit ctx: Context): Tree =
transformRefTree(tree)
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.
Done
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.
Though it added a line of code
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.
Some refactoring suggestions. Otherwise LGTM
No description provided.