Skip to content

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

Merged
merged 4 commits into from
May 7, 2018

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

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))
Copy link
Contributor

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 = {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@allanrenucci allanrenucci May 7, 2018

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

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

Copy link
Contributor

@allanrenucci allanrenucci left a 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

@nicolasstucki nicolasstucki merged commit f2814c3 into scala:master May 7, 2018
@allanrenucci allanrenucci deleted the fix-#4395 branch May 7, 2018 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants