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

Single quote error could be more helpful #10120

Closed
scabug opened this issue Dec 22, 2016 · 6 comments
Closed

Single quote error could be more helpful #10120

scabug opened this issue Dec 22, 2016 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Dec 22, 2016

http://stackoverflow.com/questions/14807767/algorithm-behind-unclosed-character-literal

This could be more beginner-friendly:

scala> 'utf-8'
<console>:1: error: unclosed character literal
'utf-8'
      ^

scala> 'utf
res1: Symbol = 'utf

scala> 'utf - 8'
<console>:1: error: unclosed character literal
'utf - 8'
        ^

scala> ''
<console>:1: error: unclosed character literal
''
^

scala> 'utf8'
<console>:1: error: unclosed character literal
'utf8'
     ^

scala> 'utf_8'
<console>:1: error: unclosed character literal
       'utf_8'
       ++++++^
@scabug
Copy link
Author

scabug commented Dec 22, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10120?orig=1
Reporter: @som-snytt
Affected Versions: 2.12.1

@scabug
Copy link
Author

scabug commented Dec 27, 2016

@som-snytt said:
There is no -Xprint:scanner. -Ydebug shows:

scala> 'utf-8'
<console>:1: error: unclosed character literal
'utf-8'
      ^
<console>:1: error: [ suppressed ] ';' expected but something found.
'utf-8'
      ^

but could actually show the scansion for the line.

@scabug
Copy link
Author

scabug commented Jan 7, 2017

@som-snytt said:
scala/scala#5629

@Jasper-M
Copy link
Member

Jasper-M commented Feb 1, 2018

The 'utf-8' message is still the same. Is that intentional?

scala> 'utf_8'
             ^
       error: unclosed character literal (or use " for string literal "utf_8")

scala> 'utf-8'
             ^
       error: unclosed character literal

@som-snytt
Copy link

som-snytt commented Feb 1, 2018

'utf-8 is scala.Symbol("utf").$minus(8) so it's not as amenable to detecting the pattern.

But it could look for scala.Symbol in the tree and offer the advice. It probably doesn't need to be too precise. Edit: not even that, the error is too low-level. If scanner returned scan errors to the parser, the parser could emit more informed messages.

Or as an approximation, downcast the scanner to grab the source line and check if this isn't the only quote on the line.

@som-snytt
Copy link

scala/scala#6298

@SethTisue SethTisue added has PR and removed has PR labels Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants