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
The analyzer differes in behaviour from dart2js/VM. It's a compile-time error for dart2js/VM.
$ cat test.dart
main() {
switch(#abc) {
case #abc:
print('abc');
break;
case #xyz:
print('xyz');
break;
}
}
$ dartanalyzer test.dart
Analyzing [test.dart]...
No issues found
$ dart2js test.dart
test.dart:3:10:
Error: 'case' expression type 'Symbol' overrides 'operator =='.
case #abc:
^^^^
Error: Compilation failed.
$ dart test.dart
'file:///usr/local/google/home/kustermann/repositories/gcloud/test.dart': error: line 3 pos 11: type class of case expression must not implement operator ==
case #abc:
^
In the prior discussions (Issue #15445 and Issue #15455) the conclusion was that the spec should allow symbols in constant maps and switch cases. The spec was changed for constant maps, but not for switch cases.
Neither the VM nor dart2js have implemented the const Map change, and both still reject symbols as both const map keys and switch case expressions.
The switch statement supports dispatching control among a large number of cases.
It is a compile-time error if the values of the expressions e_k are not either [...]
instances of the same class C, for all k in 1 .. n, or [...]
It is a compile-time error if the class C has an implementation of the
operator == other than the one inherited from Object unless the value
of the expression is a string, an integer, literal symbol or the result of
invoking a constant constructor of class Symbol.
As well, the VM, dart2js, CFE, and analyzer all now agree (use dartpad for dart2js):
$ cat 21580.dart
main() {
switch(#abc) {
case #abc:
print('abc');
break;
case #xyz:
print('xyz');
break;
}
}
$ dart --version
Dart VM version: 2.0.0-dev.63.0 (Fri Jun 15 00:42:43 2018 +0200) on "macos_x64"
$ dart 21580.dart
abc
$ dart --preview-dart-2 21580.dart
abc
$ dartanalyzer 21580.dart
Analyzing 21580.dart...
No issues found!
$ dartanalyzer --preview-dart-2 21580.dart
Analyzing 21580.dart...
No issues found!
The analyzer differes in behaviour from dart2js/VM. It's a compile-time error for dart2js/VM.
$ cat test.dart
main() {
switch(#abc) {
case #abc:
print('abc');
break;
case #xyz:
print('xyz');
break;
}
}
$ dartanalyzer test.dart
Analyzing [test.dart]...
No issues found
$ dart2js test.dart
test.dart:3:10:
Error: 'case' expression type 'Symbol' overrides 'operator =='.
case #abc:
^^^^
Error: Compilation failed.
$ dart test.dart
'file:///usr/local/google/home/kustermann/repositories/gcloud/test.dart': error: line 3 pos 11: type class of case expression must not implement operator ==
case #abc:
^
Slightly related to Issue #15445.
The text was updated successfully, but these errors were encountered: