dartanalyzer在我的枚举上产生错误

时间:2014-12-02 12:56:51

标签: enums dart

这是一个带枚举的基本代码:

enum Lock {ON, OFF}

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

}

我可以运行它,它打印出来:

Lock.ON

但是当我在代码上运行dartanalyser时:

$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.

我的枚举错误代码是错误吗?

编辑: 我的dart版本是: Dart VM version: 1.8.0 (Thu Nov 27 01:01:55 2014) on "macos_x64"

1 个答案:

答案 0 :(得分:6)

您必须使用未记录的标志:

dartanalyzer --enable-enum enum_demo.dart