You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"
The text was updated successfully, but these errors were encountered:
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 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"
The text was updated successfully, but these errors were encountered: