Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Unified Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 179293005: Check that const-map keys don't override equals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart
diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
index 69e3b45b9d02d08514b558f3b894906b061ee331..1ea01a85e38bdbc3d007b9cf76a1c7b54b4d5018 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -3098,11 +3098,32 @@ class ResolverVisitor extends MappingVisitor<Element> {
return null;
}
+ void checkConstMapKeysDontOverrideEquals(Spannable spannable,
+ MapConstant map) {
+ for (Constant key in map.keys.entries) {
+ if (!key.isObject()) continue;
+ ObjectConstant objectConstant = key;
+ DartType keyType = objectConstant.type;
+ ClassElement cls = keyType.element;
+ if (cls == compiler.stringClass) continue;
+ Element equals = cls.lookupMember('==');
+ if (equals.getEnclosingClass() != compiler.objectClass) {
+ compiler.reportError(spannable,
+ MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS,
+ {'type': keyType});
+ }
+ }
+ }
+
void analyzeConstant(Node node, {bool isConst: true}) {
addDeferredAction(enclosingElement, () {
Constant constant = compiler.constantHandler.compileNodeWithDefinitions(
node, mapping, isConst: isConst);
+ if (isConst && constant != null && constant.isMap()) {
+ checkConstMapKeysDontOverrideEquals(node, constant);
+ }
+
// The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names
// a class that will be instantiated outside the program by attaching a
// native class dispatch record referencing the interceptor.
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698