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

dartanalyser produces erros on enum #21767

Closed
DartBot opened this issue Dec 2, 2014 · 3 comments
Closed

dartanalyser produces erros on enum #21767

DartBot opened this issue Dec 2, 2014 · 3 comments
Assignees

Comments

@DartBot
Copy link

DartBot commented Dec 2, 2014

This issue was originally filed by nicolas.fran...@gmail.com


dartanalyser is failing when I analyse code with enum:

Here a basic code with enum:

enum Lock {ON, OFF}

void main(){
  var lock = Lock.ON;
  print(lock);

}
I can run it, it prints:

Lock.ON
But when I run dartanalyser on my code:

$dartanalyzer enum_demo.dart
Analyzing [enum_demo.dart]...
[error] Expected a method, getter, setter or operator declaration (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 1)
[error] Unexpected token 'enum' (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 1)
[error] Expected a method, getter, setter or operator declaration (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 11)
[error] Unexpected token '{' (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 11)
[error] Variables must be declared using the keywords 'const', 'final', 'var' or a type name (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 12)
[error] Expected to find ';' (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 16)
[error] Unexpected token '}' (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 19)
[error] Expected a method, getter, setter or operator declaration (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 19)
[warning] Undefined class 'Lock' (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 1, col 6)
[warning] Undefined name 'Lock' (/Users/nicolasfrancois/Documents/dart/enum_demo.dart, line 5, col 13)
8 errors and 2 warnings found.

I using this dart version:

Dart VM version: 1.8.0 (Thu Nov 27 01:01:55 2014) on "macos_x64"

@DartBot
Copy link
Author

DartBot commented Dec 2, 2014

This comment was originally written by @zoechi


see also http://stackoverflow.com/questions/27250038

@bwilkerson
Copy link
Member

Enum support in dartanalyzer is currently disabled by default. You can enable it by using the command-line option "--enable-enum".


Set owner to @bwilkerson.
Removed Priority-Unassigned label.
Added Priority-Medium, Area-Analyzer, Fixed labels.

@DartBot
Copy link
Author

DartBot commented Dec 3, 2014

This comment was originally written by @mezoni


Enum support in dartanalyzer is currently disabled by default. You can enable it by using the command-line option "--enable-enum".

Why Dart Team not used workaround?

You can use this code in your analyzer.

=============
import "dart:io";

void main() {
  var version = <int>[];
  _getVersion(version);
  if (version[0] >= 1 && version[1] >= 8) {
    print("I am Dart analyzer. I know that I can use enums in version $version.");
  }
}

void _getVersion(List<int> version) {
  version.clear();
  version.addAll([0, 0, 0]);
  var re = new RegExp(r"([0-9]).([0-9]).([0-9])");
  var match = re.matchAsPrefix(Platform.version);
  if (match.groupCount == 3) {
    for (var i = 0; i < 3; i++) {
      version[i] = int.parse(match.group(i + 1), onError: (e) => 0);
    }
  }
}

=============

Output:

I am Dart analyzer. I know that I can use enums in version [1, 8, 3].

This issue was closed.
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

2 participants