Skip to content
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

Failing to resolve to correct StringContext #4732

Closed
allanrenucci opened this issue Jun 27, 2018 · 2 comments
Closed

Failing to resolve to correct StringContext #4732

allanrenucci opened this issue Jun 27, 2018 · 2 comments
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala help wanted itype:bug

Comments

@allanrenucci
Copy link
Contributor

object StringContext {
  s"Hello"
}

fails to compile with Dotty and Scalac:

-- [E050] Reference Error: tests/allan/Test.scala:49:3 -------------------------
49 |  s"Hello"
   |   ^
   |   object StringContext does not take parameters

This is because the code snippet desugars to

StringContext("Hello").s()

Is this on purpose? An easy fix would be to desugar to scala.StringContext("Hello").s()

@allanrenucci allanrenucci added itype:question area:desugar Desugaring happens after parsing but before typing, see desugar.scala labels Jun 27, 2018
@SethTisue
Copy link
Member

or _root_.scala.StringContext if you want to be really paranoid

@smarter
Copy link
Member

smarter commented Jun 29, 2018

This is intentional in scalac, but I agree that it's not a feature worth preserving: https://github.com/scala/scala/blob/2.13.x/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala#L1374-L1376

lloydmeta added a commit to lloydmeta/dotty that referenced this issue Jul 8, 2018
Closes scala#4732

* Make desugared `s""` call `_root_.scala.StringContext` instead of just
  `StringContext`
* Adds a test
lloydmeta added a commit to lloydmeta/dotty that referenced this issue Jul 8, 2018
* Make desugared `s""` call `_root_.scala.StringContext` instead of just
  `StringContext`
* Add a unit test
lloydmeta added a commit to lloydmeta/dotty that referenced this issue Jul 8, 2018
* Make desugared `s""` call `_root_.scala.StringContext` instead of just
  `StringContext`
* Add a unit test
lloydmeta added a commit to lloydmeta/dotty that referenced this issue Jul 8, 2018
* 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
allanrenucci added a commit that referenced this issue Jul 10, 2018
Fix #4732: Root the desugared call to StringContext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala help wanted itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants