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
Comments
Added this to the Later milestone. |
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. |
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". |
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'. |
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. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
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. |
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;
^
The text was updated successfully, but these errors were encountered: