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

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

Issue 19802003: Report an error if a const constructor calls a non-const constructor. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 Set<Node> get superUses; 9 Set<Node> get superUses;
10 10
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor, 1080 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor,
1081 isSuperCall, 1081 isSuperCall,
1082 call); 1082 call);
1083 Selector constructorSelector = 1083 Selector constructorSelector =
1084 visitor.getRedirectingThisOrSuperConstructorSelector(call); 1084 visitor.getRedirectingThisOrSuperConstructorSelector(call);
1085 FunctionElement calledConstructor = 1085 FunctionElement calledConstructor =
1086 lookupTarget.lookupConstructor(constructorSelector); 1086 lookupTarget.lookupConstructor(constructorSelector);
1087 1087
1088 final bool isImplicitSuperCall = false; 1088 final bool isImplicitSuperCall = false;
1089 final SourceString className = lookupTarget.name; 1089 final SourceString className = lookupTarget.name;
1090 verifyThatConstructorMatchesCall(calledConstructor, 1090 verifyThatConstructorMatchesCall(constructor,
1091 calledConstructor,
1091 selector, 1092 selector,
1092 isImplicitSuperCall, 1093 isImplicitSuperCall,
1093 call, 1094 call,
1094 className, 1095 className,
1095 constructorSelector); 1096 constructorSelector);
1096 1097
1097 visitor.useElement(call, calledConstructor); 1098 visitor.useElement(call, calledConstructor);
1098 visitor.world.registerStaticUse(calledConstructor); 1099 visitor.world.registerStaticUse(calledConstructor);
1099 return calledConstructor; 1100 return calledConstructor;
1100 } 1101 }
(...skipping 16 matching lines...) Expand all
1117 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor, 1118 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor,
1118 isSuperCall, 1119 isSuperCall,
1119 functionNode); 1120 functionNode);
1120 Selector constructorSelector = new Selector.callDefaultConstructor( 1121 Selector constructorSelector = new Selector.callDefaultConstructor(
1121 visitor.enclosingElement.getLibrary()); 1122 visitor.enclosingElement.getLibrary());
1122 Element calledConstructor = lookupTarget.lookupConstructor( 1123 Element calledConstructor = lookupTarget.lookupConstructor(
1123 constructorSelector); 1124 constructorSelector);
1124 1125
1125 final SourceString className = lookupTarget.name; 1126 final SourceString className = lookupTarget.name;
1126 final bool isImplicitSuperCall = true; 1127 final bool isImplicitSuperCall = true;
1127 verifyThatConstructorMatchesCall(calledConstructor, 1128 verifyThatConstructorMatchesCall(constructor,
1129 calledConstructor,
1128 callToMatch, 1130 callToMatch,
1129 isImplicitSuperCall, 1131 isImplicitSuperCall,
1130 functionNode, 1132 functionNode,
1131 className, 1133 className,
1132 constructorSelector); 1134 constructorSelector);
1133 1135
1134 visitor.world.registerStaticUse(calledConstructor); 1136 visitor.world.registerStaticUse(calledConstructor);
1135 } 1137 }
1136 } 1138 }
1137 1139
1138 void verifyThatConstructorMatchesCall( 1140 void verifyThatConstructorMatchesCall(
1141 FunctionElement caller,
1139 FunctionElement lookedupConstructor, 1142 FunctionElement lookedupConstructor,
1140 Selector call, 1143 Selector call,
1141 bool isImplicitSuperCall, 1144 bool isImplicitSuperCall,
1142 Node diagnosticNode, 1145 Node diagnosticNode,
1143 SourceString className, 1146 SourceString className,
1144 Selector constructorSelector) { 1147 Selector constructorSelector) {
1145 if (lookedupConstructor == null 1148 if (lookedupConstructor == null
1146 || !lookedupConstructor.isGenerativeConstructor()) { 1149 || !lookedupConstructor.isGenerativeConstructor()) {
1147 var fullConstructorName = 1150 var fullConstructorName =
1148 visitor.compiler.resolver.constructorNameForDiagnostics( 1151 visitor.compiler.resolver.constructorNameForDiagnostics(
1149 className, 1152 className,
1150 constructorSelector.name); 1153 constructorSelector.name);
1151 MessageKind kind = isImplicitSuperCall 1154 MessageKind kind = isImplicitSuperCall
1152 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT 1155 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT
1153 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; 1156 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR;
1154 visitor.compiler.reportErrorCode( 1157 visitor.compiler.reportErrorCode(
1155 diagnosticNode, kind, {'constructorName': fullConstructorName}); 1158 diagnosticNode, kind, {'constructorName': fullConstructorName});
1156 } else { 1159 } else {
1157 if (!call.applies(lookedupConstructor, visitor.compiler)) { 1160 if (!call.applies(lookedupConstructor, visitor.compiler)) {
1158 MessageKind kind = isImplicitSuperCall 1161 MessageKind kind = isImplicitSuperCall
1159 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT 1162 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT
1160 : MessageKind.NO_MATCHING_CONSTRUCTOR; 1163 : MessageKind.NO_MATCHING_CONSTRUCTOR;
1161 visitor.compiler.reportErrorCode(diagnosticNode, kind); 1164 visitor.compiler.reportErrorCode(diagnosticNode, kind);
1165 } else if (caller.modifiers.isConst()
1166 && !lookedupConstructor.modifiers.isConst()) {
1167 visitor.compiler.reportErrorCode(
1168 diagnosticNode, MessageKind.CONST_CALLS_NON_CONST);
1162 } 1169 }
1163 } 1170 }
1164 } 1171 }
1165 1172
1166 FunctionElement resolveRedirection(FunctionElement constructor, 1173 FunctionElement resolveRedirection(FunctionElement constructor,
1167 FunctionExpression functionNode) { 1174 FunctionExpression functionNode) {
1168 if (functionNode.initializers == null) return null; 1175 if (functionNode.initializers == null) return null;
1169 Link<Node> link = functionNode.initializers.nodes; 1176 Link<Node> link = functionNode.initializers.nodes;
1170 if (!link.isEmpty && Initializers.isConstructorRedirect(link.head)) { 1177 if (!link.isEmpty && Initializers.isConstructorRedirect(link.head)) {
1171 return resolveSuperOrThisForSend(constructor, functionNode, link.head); 1178 return resolveSuperOrThisForSend(constructor, functionNode, link.head);
(...skipping 2898 matching lines...) Expand 10 before | Expand all | Expand 10 after
4070 return e; 4077 return e;
4071 } 4078 }
4072 4079
4073 /// Assumed to be called by [resolveRedirectingFactory]. 4080 /// Assumed to be called by [resolveRedirectingFactory].
4074 Element visitReturn(Return node) { 4081 Element visitReturn(Return node) {
4075 Node expression = node.expression; 4082 Node expression = node.expression;
4076 return finishConstructorReference(visit(expression), 4083 return finishConstructorReference(visit(expression),
4077 expression, expression); 4084 expression, expression);
4078 } 4085 }
4079 } 4086 }
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