-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Literal symbols are not accepted as const map keys. #15442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Added Area-Analyzer, Triaged labels. |
Two bugs here: an analyzer bug, and a VM bug. I've dedicated this bug to the analyzer and the corresponding VM bug is issue #15445. |
This comment was originally written by tiagomz...@gmail.com Same warning with class literals. class A {} |
Added this to the 1.1 milestone. |
Class literals (Type objects) suffer from the same problem as symbols: They override the operator== method of Object, so they are not allowed as const map keys. They override equals because we didn't want to canonicalize the potentially infinite number of Type objects that a program can create due to risk of memory leaking, but we still want the Type objects to be equal if they represent the same Type. |
Duplicate? See: #13245 |
https://codereview.chromium.org/113143004/ (bleeding edge revision 31303) Set owner to @bwilkerson. |
If "fixed" means not giving a warning, then it's a bug. See: https://groups.google.com/a/dartlang.org/forum/?fromgroups#!topic/misc/TPe9-SfDRps Added Triaged label. |
"The static type of a symbol literal is Symbol." Neither dart:core::Symbol nor dart:core::Type implements nor inherits an implementation of == other than the one in Object. (They are both abstract classes with no explicit superclass, mixins, or interfaces.) Therefore, based on the static type information, I don't believe that there is suppose to be an error here. The analyzer cannot be expected to use the run-time type of a literal when it isn't given in the specification. Please let me know if my reasoning is faulty. (I would almost argue that it's a bug in the VM that the internal Symbol defines ==, but user code can have the same problem too. Perhaps we should define == on dart:core::Symbol in order to make it possible to catch this problem in the analyzer.) Added Fixed label. |
This issue was originally filed by tiagom...@gmail.com
What steps will reproduce the problem?
class A {}
class B {}
main() {
var map = const <Symbol, int>{#A:0, #B:1};
print(map);
}
the Editor shows this warning 'Keys in a map cannot be equal'
and running the code produces the error: 'key value must not implement operator =='.
The same behavior occurs with var map = const <Symbol, int>{const Symbol('A'):0, const Symbol('B'):1}
It works removing the const keyword but the DartEditor still shows the warning.
What version of the product are you using? On what operating system?
Editor: 1.0.1_r30657 (2013-11-25)
OS: Mac OS X - x86_64 (10.9)
The text was updated successfully, but these errors were encountered: