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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Setlet<Node> get superUses; 9 Setlet<Node> get superUses;
10 10
(...skipping 3080 matching lines...) Expand 10 before | Expand all | Expand 10 after
3091 } else if (isMirrorsUsedConstant) { 3091 } else if (isMirrorsUsedConstant) {
3092 compiler.mirrorUsageAnalyzerTask.validate(node, mapping); 3092 compiler.mirrorUsageAnalyzerTask.validate(node, mapping);
3093 } 3093 }
3094 if (node.isConst()) { 3094 if (node.isConst()) {
3095 analyzeConstant(node); 3095 analyzeConstant(node);
3096 } 3096 }
3097 3097
3098 return null; 3098 return null;
3099 } 3099 }
3100 3100
3101 void checkConstMapKeysDontOverrideEquals(Spannable spannable,
3102 MapConstant map) {
3103 for (Constant key in map.keys.entries) {
3104 if (!key.isObject()) continue;
3105 ObjectConstant objectConstant = key;
3106 DartType keyType = objectConstant.type;
3107 ClassElement cls = keyType.element;
3108 if (cls == compiler.stringClass) continue;
3109 Element equals = cls.lookupMember('==');
3110 if (equals.getEnclosingClass() != compiler.objectClass) {
3111 compiler.reportError(spannable,
3112 MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS,
3113 {'type': keyType});
3114 }
3115 }
3116 }
3117
3101 void analyzeConstant(Node node, {bool isConst: true}) { 3118 void analyzeConstant(Node node, {bool isConst: true}) {
3102 addDeferredAction(enclosingElement, () { 3119 addDeferredAction(enclosingElement, () {
3103 Constant constant = compiler.constantHandler.compileNodeWithDefinitions( 3120 Constant constant = compiler.constantHandler.compileNodeWithDefinitions(
3104 node, mapping, isConst: isConst); 3121 node, mapping, isConst: isConst);
3105 3122
3123 if (isConst && constant != null && constant.isMap()) {
3124 checkConstMapKeysDontOverrideEquals(node, constant);
3125 }
3126
3106 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names 3127 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names
3107 // a class that will be instantiated outside the program by attaching a 3128 // a class that will be instantiated outside the program by attaching a
3108 // native class dispatch record referencing the interceptor. 3129 // native class dispatch record referencing the interceptor.
3109 if (argumentsToJsInterceptorConstant != null && 3130 if (argumentsToJsInterceptorConstant != null &&
3110 argumentsToJsInterceptorConstant.contains(node)) { 3131 argumentsToJsInterceptorConstant.contains(node)) {
3111 if (constant.isType()) { 3132 if (constant.isType()) {
3112 TypeConstant typeConstant = constant; 3133 TypeConstant typeConstant = constant;
3113 if (typeConstant.representedType is InterfaceType) { 3134 if (typeConstant.representedType is InterfaceType) {
3114 world.registerInstantiatedType(typeConstant.representedType, 3135 world.registerInstantiatedType(typeConstant.representedType,
3115 mapping); 3136 mapping);
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 return finishConstructorReference(visit(expression), 4544 return finishConstructorReference(visit(expression),
4524 expression, expression); 4545 expression, expression);
4525 } 4546 }
4526 } 4547 }
4527 4548
4528 /// Looks up [name] in [scope] and unwraps the result. 4549 /// Looks up [name] in [scope] and unwraps the result.
4529 Element lookupInScope(Compiler compiler, Node node, 4550 Element lookupInScope(Compiler compiler, Node node,
4530 Scope scope, String name) { 4551 Scope scope, String name) {
4531 return Elements.unwrap(scope.lookup(name), compiler, node); 4552 return Elements.unwrap(scope.lookup(name), compiler, node);
4532 } 4553 }
OLDNEW
« 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