2014-12-02 42 views
3

这里一个基本的代码枚举误差修改:dartanalyser产生在我的枚举

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 VM version: 1.8.0 (Thu Nov 27 01:01:55 2014) on "macos_x64"

+0

达特什么版本您使用的? ('dart --version') – 2014-12-02 13:01:36

+0

我认为这是最后一个: Dart VM版本:1.8.0(Thu Nov 27 01:01:55 2014)on“macos_x64” – 2014-12-02 13:11:29

+0

Dart VM版本:1.9.0-edge。 42061(2014年12月2日星期二02:49:13)关于“linux_x64”。 DartEditor不会抱怨,但是从命令行运行'dartanalyzer'确实如此。我认为你应该在http://dartbug.com/new – 2014-12-02 13:28:46

回答

6

你必须使用一个未公开的标志:

dartanalyzer --enable-enum enum_demo.dart 
+0

好的!我认为这是一个错误,因为枚举应该在Dart 1.8.0之前不支持标志的情况下被支持。据我所知,只有'await' /'async'仍然是实验性的。 – 2014-12-02 13:31:14

+0

由于您必须手动在编辑器中启用enums_,因此使用标志看起来很好。但是这个标志应该用'dartanalyzer --help'显示。 – 2014-12-02 13:35:04

+0

以下是相关问题http://dartbug.com/21415。我记得读过这个评论https://code.google.com/p/dart/issues/detail?id=21416#c10,但它似乎只适用于虚拟机,而不适用于分析器。 – 2014-12-02 13:41:45