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

weird string interpolation parsing failure #7919

Closed
scabug opened this issue Oct 19, 2013 · 7 comments
Closed

weird string interpolation parsing failure #7919

scabug opened this issue Oct 19, 2013 · 7 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 19, 2013

object foo {
  val foo = if (bar) s"x" else s""
  val bar = true
}

fails with:

test.scala:3: error: ';' expected but 'val' found.
val bar = true
^
one error found
@scabug
Copy link
Author

scabug commented Oct 19, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7919?orig=1
Reporter: @densh
Affected Versions: 2.11.0-M6

@scabug
Copy link
Author

scabug commented Oct 26, 2013

@paulp said (edited on Oct 26, 2013 7:05:28 PM UTC):
Reduced. It's losing the newline token after a completely empty interpolated string. If it's s"1", or a semicolon instead of a newline, or two newlines, or a comment after the empty string, it compiles.

class A {
  s""
  5
}

@scabug
Copy link
Author

scabug commented Jan 24, 2014

@densh said (edited on Jan 24, 2014 5:34:04 PM UTC):
I've spend this day running the Scanner through debugger. The only thing I've found out it that the failure to insert the semicolon is caused by afterLineEnd() call on line https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala#L332. This call fail to return true on the last string interpolation token and thus semicolon isn't inserted after it. The function itself is based on dozen of mutable variables that appear to be out of sync in that particular case https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala#L372. A number of mutable variables involved seem to be beyond my limit of code comprehension. Maybe somebody else will have a better luck with it.

@scabug
Copy link
Author

scabug commented Jan 24, 2014

@som-snytt said:
To detect triple-quotes, it's using CharArrayReader.nextRawChar instead of nextChar, so it's not detecting "potentialLineEnd".

@scabug
Copy link
Author

scabug commented Jan 24, 2014

@som-snytt said:
scala/scala#3411

@scabug
Copy link
Author

scabug commented Jan 25, 2014

@densh said:
THANK YOU

@scabug scabug closed this as completed Jan 25, 2014
@scabug
Copy link
Author

scabug commented Jan 25, 2014

@som-snytt said:
Quasiquotes are thanks enough.

This was a quickie because I'd just looked at that other EOL bug.

@scabug scabug added this to the 2.11.0-RC1 milestone Apr 7, 2017
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

No branches or pull requests

2 participants