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

Dart VM: Unexpected syntax error reported #13966

Closed
fsc8000 opened this issue Oct 10, 2013 · 8 comments
Closed

Dart VM: Unexpected syntax error reported #13966

fsc8000 opened this issue Oct 10, 2013 · 8 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior

Comments

@fsc8000
Copy link
Contributor

fsc8000 commented Oct 10, 2013

Compiling the following code with Dart VM gives an unexpected error message:


const final X = 42;

main() { }


$ out/ReleaseIA32/dart e1.dart
'file:///media/SSD/dart7/dart/e1.dart': Error: line 1 pos 1: unexpected token 'const'
const final X = 42;
^

$ out/ReleaseIA32/dart-sdk/bin/dart2js e1.dart
e1.dart:1:7: Error: Can't have modifier 'final' here.
Try removing 'final'.
const final X = 42;
      ^^^^^
Error: Compilation failed.

The dart2js error looks correct (and more helpful with trying to suggest a correction). The VM reports the error at position 1:1 and 'const' as unexpected which seems wrong.

Compiling "final const X = 42" gives another error on the VM. This time the position is correct:

'file:///media/SSD/dart7/dart/e1.dart': Error: line 1 pos 7: variable name expected
final const X = 42;
      ^

@iposva-google
Copy link
Contributor

Added this to the Later milestone.

@lrhn
Copy link
Member

lrhn commented Oct 10, 2013

The error is that you can't have both final and const. The most correct highlighting would be to highlight both and say that they are mutually exclusive.

@DartBot
Copy link

DartBot commented Oct 10, 2013

This comment was originally written by @mhausner


Sure. But in order to give more accurate error messages, you have to make an educated guess as to what the illegal declaration was intended to be. Looking at this example as a human, it's obvious, but to a parser it is not obvious. You can add heuristics and they may work for some cases, but not in other cases and you are back to square one. I'm tempted to just make this particular error say "syntax error".

@fsc8000
Copy link
Contributor Author

fsc8000 commented Oct 11, 2013

Apart from the error message which can be more or less helpful, the main issue was the position of the error which should be trivial to fix: The error clearly occurs after 'const' when encountering the unexpected 'final', and not before 'const'.

@DartBot
Copy link

DartBot commented Oct 11, 2013

This comment was originally written by @mhausner


The explanation for the error location follows from what I said earlier: the compiler doesn't know what to do with the entire line, so it reports the error on the first token of the declaration. I don't want to put more hacks/heuristics into the compiler that just solve this one case. At least not at this point.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@DartBot
Copy link

DartBot commented Apr 3, 2015

This comment was originally written by @mhausner


As I outlined in previous comments, there is no bug here. I don't want to add more heuristics into the parser that guess what an illegal sequence of tokens could have been meant to be.


Added AsDesigned label.

@fsc8000 fsc8000 added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior labels Apr 3, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

6 participants