-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Closed
Copy link
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work oncustomer-dart2jsfront-end-fastafront-end-missing-errorfront-end-requires-constant-evaluationIssue that can't be solved without evaluating compile-time constantsIssue that can't be solved without evaluating compile-time constantslegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.
Milestone
Description
The spec doesn't allow const values that implement == to be used as keys in const maps, or as cases on switch statements.
The CFE is currently not producing a compile-time error for it.
Here is an example:
class A {
final x;
const A(this.x);
operator==(y) => x < y.x;
}
const one = const A(1);
const two = const A(2);
const map = const {one: 1, two: 2};
main() {
print(map[one]);
print(map[two]);
print(one == two);
}Then:
> dart a.dart
'/a.dart': error: line 11 pos 20: key value must not implement operator ==
const map = const {one: 1, two: 2};
^
> dart --preview-dart-2 a.dart
2
null
true
I wanted to file a bug for this issue because it accidentally hides a problem in dart2js, that Type cannot be used in these const contexts (see #17207), the sooner we handle this, the lower the chance we'll make a breaking change later on.
Metadata
Metadata
Assignees
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work oncustomer-dart2jsfront-end-fastafront-end-missing-errorfront-end-requires-constant-evaluationIssue that can't be solved without evaluating compile-time constantsIssue that can't be solved without evaluating compile-time constantslegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.