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

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: Update comment and add other test. 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
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..a5cc401ac61b30e4ca1e198ca9051e9b9348ac47 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -3098,11 +3098,33 @@ class ResolverVisitor extends MappingVisitor<Element> {
return null;
}
+ void checkConstMapKeysDontOverrideEquals(Spannable spannable,
+ MapConstant map) {
+ List<Constant> keys = map.keys.entries;
karlklose 2014/03/03 08:58:45 You can inline `keys`.
floitsch 2014/03/03 09:52:32 Done.
+ for (Constant key in keys) {
+ 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.

Powered by Google App Engine
This is Rietveld 408576698