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

Need better recovery for statements at the top level #10554

Open
DartBot opened this issue May 9, 2013 · 11 comments
Open

Need better recovery for statements at the top level #10554

DartBot opened this issue May 9, 2013 · 11 comments
Labels
analyzer-recovery area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented May 9, 2013

This issue was originally filed by @orian


Reproduce:
class SomeClass {
  int id;
  SomeClass(this.id);
}
var VAL1 = new SomeClass(1);
var VAL2 = new SomeClass(2);
var valById = {};
var allValues = [VAL1, VAL2];
allValues.forEach((enum) => result[enum.id] = enum);

Error shown by Eclipse:
Multiple markers at this line
    - Expected to find ';'
    - Unexpected token
     'enum'
    - Undefined name ''
    - Unexpected token ')'
    - Undefined name ''
    - Undefined name ''
    - Undefined name ''
    - Undefined name ''
    - Expected a statement
    - Expected to find ';'
    - Expected to find ';'
    - Unexpected token
     'enum'
    - Unexpected token ']'
    - Expected a statement
    - Expected to find ';'
    - Expected to find ';'
    - Expected a statement
    - Unexpected token
     'enum'
    - Expected to find ';'
    - Unexpected token ')'
    - Expected to find ';'
    - Unexpected token '=>'
    - Expected to find ']'
    - Expected to find ')'
    - Undefined name ''
    - Undefined name ''
    - Undefined name ''
    - Undefined name ''

What is the expected output?
"Wrong use of keyword", "Keyword used as a variable name" etc.

What version of the product are you using? On what operating system?
0.5.5_r22416, Linux,

Please provide any additional information below.
Was there an official announcment of "enum" becoming reserved keyword?

@bwilkerson
Copy link
Member

Set owner to @bwilkerson.
Added this to the M6 milestone.
Added Area-Analyzer, Triaged labels.

@bwilkerson
Copy link
Member

Removed this from the M6 milestone.
Added this to the M7 milestone.

@jwren
Copy link
Member

jwren commented Sep 19, 2013

M7 -> M8


Removed this from the M7 milestone.
Added this to the M8 milestone.

@bwilkerson
Copy link
Member

Removed this from the M8 milestone.
Added this to the Later milestone.

@bwilkerson
Copy link
Member

Although 'enum' is a reserved word, the bigger issue here is poor error recovery when encountering a statement at the top level.


Changed the title to: "Need better recovery for statements at the top level".

@bwilkerson
Copy link
Member

Added Analyzer-Recovery label.

@bwilkerson
Copy link
Member

Removed Type-Defect label.
Added Type-Enhancement label.

@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 DartBot added Priority-Medium area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-recovery labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@srawlins
Copy link
Member

This one is wild. It still produces a 11 errors/warnings! DartPad repro (warnings are truncated to first 5).

[error] Unexpected token '(' (/Users/srawlins/xy.dart, line 9, col 18)
[error] Expected a method, getter, setter or operator declaration (/Users/srawlins/xy.dart, line 9, col 18)
[error] Expected a method, getter, setter or operator declaration (/Users/srawlins/xy.dart, line 9, col 35)
[error] Unexpected token '[' (/Users/srawlins/xy.dart, line 9, col 35)
[error] The name '' is already defined (/Users/srawlins/xy.dart, line 9, col 35)
[error] The name '' is already defined (/Users/srawlins/xy.dart, line 9, col 43)
[error] Expected a method, getter, setter or operator declaration (/Users/srawlins/xy.dart, line 9, col 43)
[error] Unexpected token ']' (/Users/srawlins/xy.dart, line 9, col 43)
[warning] Undefined class 'allValues.forEach' (/Users/srawlins/xy.dart, line 9, col 1)
[warning] Undefined class 'result' (/Users/srawlins/xy.dart, line 9, col 29)
[warning] Undefined class 'id' (/Users/srawlins/xy.dart, line 9, col 41)
8 errors and 3 warnings found.

If you wrap the last line (the forEach statement) in a function, like void main() { ... }, you instead get 29 errors and 1 warning!!!

If you instead convert each case of the enum "variable" to enumx, you get 14 errors and 5 warnings!!!

So I think the 2 bugs in this issue are:

  • Improve error recovery on statements that don't work top-level (in this case a method call on an object)
  • Improve error recovery on keywords in method definitions, or for loop conditions, etc.

e.g. each of the three examples below produces similar crazy errors:

void main() {
  //for (enum in [1,2,3]) {
  //  print(enum);
  //}

  //for (in in [1,2,3]) {
  //  print(in);
  //}

  for (continue in [1,2,3]) {
    print(continue);
  }
}

@bwilkerson bwilkerson removed their assignment Aug 15, 2016
@srawlins
Copy link
Member

srawlins commented Aug 7, 2019

3-year update:

  • Original code now produces 8 errors (down from 11).
  • Wrapping last statement in a function (like fn() => ...) reduces it to 4 errors, each appropriately about mis-using enum as an identifier.
  • Replacing each enum identifier with enumx now produces 7 errors (down from 14).

The following code still produces too many errors:

void main() {
  // 4 errors.
  for (enum in [1,2,3]) {
    print(enum);
  }

  // 4 errors.
  for (in in [1,2,3]) {
    print(in);
  }

  // 5 errors.
  for (continue in [1,2,3]) {
    print(continue);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-recovery area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants