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 analyzer and dart2js disagree about 'static' as variable name #19552

Closed
DartBot opened this issue Jun 19, 2014 · 3 comments
Closed

Dart analyzer and dart2js disagree about 'static' as variable name #19552

DartBot opened this issue Jun 19, 2014 · 3 comments
Assignees
Labels
closed-obsolete Closed as the reported issue is no longer relevant P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@DartBot
Copy link

DartBot commented Jun 19, 2014

This issue was originally filed by @butlermatt


Using this program:

void main() {
  var static = 'Hello World';
  print(static);
}

This program works in dart vm with and without checked mode. This program passes the dartanalzyer however dart2js throws an error:

Error: Expected identifier, but got '='.
  var static = 'Hello World';
             ^
Error Compilation failed.

This occurs with Dart SDK version 1.5.0-dev.4.2 and 1.5.0-dev.4.15 in 64-bit linux. (Editor also shows no errors)

@lrhn
Copy link
Member

lrhn commented Jun 19, 2014

The analyzer is correct. The word "static" is not a keyword in dart, only a "built-in identifier". It is allowed as the name of a variable. It just can't be the name of a class, typedef or type parameter, or used as a type annotation.

That means that "var static = 42;" is correct, and "static var x = 42;" can be too (inside a class), but since static must come before the type/var/final, and the name must come after, there should not be any ambiguity.

So, you should be able to do "static int static = 42;".


cc @peter-ahe-google.
Added Area-Dart2JS, Triaged labels.

@floitschG
Copy link
Contributor

Set owner to @johnniwinther.
Removed Priority-Unassigned label.
Added Priority-Low label.

@peter-ahe-google
Copy link
Contributor

I agree with Lasse. dart2js handles this better for top-level variables and class members since these are implemented using "findMemberName" in the parser.

There is a similar issue for local functions:

void main() {
  static() => 'Hello World';
  print(static);
}

Gives:

Error: Expected identifier, but got '('.
  static() => 'Hello World';
        ^

@DartBot DartBot added Type-Defect P3 A lower priority bug or feature request web-dart2js labels Jun 19, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Mar 1, 2016
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-obsolete Closed as the reported issue is no longer relevant P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

7 participants