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

Regression in parsing XML symbols used in old if-else syntax #16459

Closed
WojciechMazur opened this issue Dec 2, 2022 · 2 comments · Fixed by #19531
Closed

Regression in parsing XML symbols used in old if-else syntax #16459

WojciechMazur opened this issue Dec 2, 2022 · 2 comments · Fixed by #19531
Assignees
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Dec 2, 2022

Compiler version

3.2.1

Minimized code

//> using lib "org.scala-lang.modules::scala-xml:2.1.0"

@main def Test() = {
  val elem = if(true) {
    <script type="text/javascript">
      'location.reload()'
      'foo bar'
    </script>
  } else <div>empty</div>

  println(elem)
}

Replacing parentheses with new if/then syntax allows to compile this code

// works with both `if true then ...` and `if true then { ...` 
//> using lib "org.scala-lang.modules::scala-xml:2.1.0"

@main def Test() = {
  val elem = if true then {
    <script type="text/javascript">
      'location.reload()'
      'foo bar'
    </script>
  } else <div>empty</div>

  println(elem)
}

Output

[error] ./test.sc:7:25: unclosed character literal
[error]       'location.reload()'
[error]      
[error] ./test.sc:8:15: unclosed character literal
[error]       'foo bar'
[error]     

Expectation

Should compile with output:

<script type="text/javascript">
      'location.reload()'
    </script>

@i10416
Copy link
Contributor

i10416 commented Dec 5, 2022

May I take this issue?

@nicolasstucki
Copy link
Contributor

@i10416, you may take this issue

i10416 added a commit to i10416/dotty that referenced this issue Jan 25, 2024
The parser could not parse `if expr` that contains single-quoted text(s) inside
XML literal with newline(s) because `followedByToken`, which is used to detect `do` or `then` token after `if`,
unintentionally consumed XMLSTART symbol, which prevented the parser from delegating parse to XML parser.
odersky added a commit that referenced this issue Feb 1, 2024
close #16459 

The parser could not parse `if expr` that contains single-quoted text(s)
inside XML literal with newline(s) because `followedByToken`, which is
used to detect `do` or `then` token after `if`, unintentionally consumed
XMLSTART symbol, which prevented the parser from delegating parse to XML
parser.
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur pushed a commit that referenced this issue Jun 28, 2024
The parser could not parse `if expr` that contains single-quoted text(s) inside
XML literal with newline(s) because `followedByToken`, which is used to detect `do` or `then` token after `if`,
unintentionally consumed XMLSTART symbol, which prevented the parser from delegating parse to XML parser.

[Cherry-picked 1fc27df]
WojciechMazur pushed a commit that referenced this issue Jun 30, 2024
The parser could not parse `if expr` that contains single-quoted text(s) inside
XML literal with newline(s) because `followedByToken`, which is used to detect `do` or `then` token after `if`,
unintentionally consumed XMLSTART symbol, which prevented the parser from delegating parse to XML parser.

[Cherry-picked 1fc27df]
WojciechMazur added a commit that referenced this issue Jul 1, 2024
Backports #19531 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants