-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4732: Root the desugared call to StringContext #4779
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
Fix #4732: Root the desugared call to StringContext #4779
Conversation
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
1ac8205
to
32c82b5
Compare
* Make desugared `s""` call `_root_.scala.StringContext` instead of just `StringContext` to fix the initial issue * Add a unit test to lock in the change * Update StringInterpolatorOpt#unapply so that the StringInterpolator optimistation can work with the new change
6e5ebce
to
426011b
Compare
val scalaPkg = Select(rootPkg, nme.scala_) | ||
Select(scalaPkg, nme.StringContext) | ||
} | ||
Apply(Select(Apply(rootedStringContext, strs), id), elems) |
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.
Maybe rootedStringContext
can be replaced with ref(defn.StringContextModule)
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.
No, Desugar produces untyped trees
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.
Oh, I missed that. Indore my comment
val rootedStringContext = { | ||
val rootPkg = Ident(nme.ROOTPKG) | ||
val scalaPkg = Select(rootPkg, nme.scala_) | ||
Select(scalaPkg, nme.StringContext) |
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.
As a shortcut, you can use scalaDot(nme.StringContext)
val scalaPkg = Select(rootPkg, nme.scala_) | ||
Select(scalaPkg, nme.StringContext) | ||
} | ||
Apply(Select(Apply(rootedStringContext, strs), id), elems) |
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.
As suggested by @smarter, you can rewrite as
Apply(Select(Apply(scalaDot(nme.StringContext), strs), id), elems)
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.
Good idea. Done.
@@ -36,7 +36,7 @@ class StringInterpolatorOpt extends MiniPhase { | |||
def unapply(tree: Select)(implicit ctx: Context): Boolean = { | |||
tree.symbol.eq(defn.StringContextModule_apply) && { | |||
val qualifier = tree.qualifier | |||
qualifier.isInstanceOf[Ident] && qualifier.symbol.eq(defn.StringContextModule) | |||
qualifier.isInstanceOf[Select] && qualifier.symbol.eq(defn.StringContextModule) |
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.
Thinking about it, the first test might not be needed. The method could be rewritten as:
def unapply(tree: Select)(implicit ctx: Context): Boolean =
tree.symbol.eq(defn.StringContextModule_apply) &&
tree.qualifier.symbol.eq(defn.StringContextModule)
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.
Indeed, it seemed a bit fragile. Removed.
tests/run/rooted_stringcontext.scala
Outdated
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
println(StringContext.s) |
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 would remove the check file and simply do assert(StringContext.s == "Answer: 42")
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.
* Simplify grabbing of rooted handle to StringContext * Simplify StringContext tree unapply * Remove check file for test and use an assert instead
@allanrenucci Just addressed all your feedback + @smarter 's suggestions; please have another look when you can 😄 |
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.
LGTM. Thanks @lloydmeta!
Closes #4732
s""
call_root_.scala.StringContext
instead of justStringContext