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

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

Issue 23503035: Emit a compile-time error on const constructors with a body. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (element.isPatched) { 354 if (element.isPatched) {
355 checkMatchingPatchSignatures(element, element.patch); 355 checkMatchingPatchSignatures(element, element.patch);
356 element = element.patch; 356 element = element.patch;
357 } 357 }
358 return compiler.withCurrentElement(element, () { 358 return compiler.withCurrentElement(element, () {
359 FunctionExpression tree = element.parseNode(compiler); 359 FunctionExpression tree = element.parseNode(compiler);
360 if (tree.modifiers.isExternal()) { 360 if (tree.modifiers.isExternal()) {
361 error(tree, MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 361 error(tree, MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
362 return; 362 return;
363 } 363 }
364 if (isConstructor) { 364 if (isConstructor || element.isFactoryConstructor()) {
365 if (tree.returnType != null) { 365 if (tree.returnType != null) {
366 error(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE); 366 error(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE);
367 } 367 }
368 if (element.modifiers.isConst() &&
369 tree.hasBody() &&
370 !tree.isRedirectingFactory) {
371 compiler.reportError(tree, MessageKind.CONST_CONSTRUCTOR_HAS_BODY);
372 }
368 } 373 }
374
369 ResolverVisitor visitor = visitorFor(element); 375 ResolverVisitor visitor = visitorFor(element);
370 visitor.useElement(tree, element); 376 visitor.useElement(tree, element);
371 visitor.setupFunction(tree, element); 377 visitor.setupFunction(tree, element);
372 378
373 if (isConstructor && !element.isForwardingConstructor) { 379 if (isConstructor && !element.isForwardingConstructor) {
374 // Even if there is no initializer list we still have to do the 380 // Even if there is no initializer list we still have to do the
375 // resolution in case there is an implicit super constructor call. 381 // resolution in case there is an implicit super constructor call.
376 InitializerResolver resolver = new InitializerResolver(visitor); 382 InitializerResolver resolver = new InitializerResolver(visitor);
377 FunctionElement redirection = 383 FunctionElement redirection =
378 resolver.resolveInitializers(element, tree); 384 resolver.resolveInitializers(element, tree);
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 resolveFieldInitializer(constructor, init); 1237 resolveFieldInitializer(constructor, init);
1232 } else if (link.head.asSend() != null) { 1238 } else if (link.head.asSend() != null) {
1233 final Send call = link.head.asSend(); 1239 final Send call = link.head.asSend();
1234 if (Initializers.isSuperConstructorCall(call)) { 1240 if (Initializers.isSuperConstructorCall(call)) {
1235 if (resolvedSuper) { 1241 if (resolvedSuper) {
1236 error(call, MessageKind.DUPLICATE_SUPER_INITIALIZER); 1242 error(call, MessageKind.DUPLICATE_SUPER_INITIALIZER);
1237 } 1243 }
1238 resolveSuperOrThisForSend(constructor, functionNode, call); 1244 resolveSuperOrThisForSend(constructor, functionNode, call);
1239 resolvedSuper = true; 1245 resolvedSuper = true;
1240 } else if (Initializers.isConstructorRedirect(call)) { 1246 } else if (Initializers.isConstructorRedirect(call)) {
1241 // Check that there is no body (Language specification 7.5.1). 1247 // Check that there is no body (Language specification 7.5.1). If the
1242 if (functionNode.hasBody()) { 1248 // constructor is also const, we already reported an error in
1249 // [resolveMethodElement].
1250 if (functionNode.hasBody() && !constructor.modifiers.isConst()) {
1243 error(functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY); 1251 error(functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY);
1244 } 1252 }
1245 // Check that there are no other initializers. 1253 // Check that there are no other initializers.
1246 if (!initializers.tail.isEmpty) { 1254 if (!initializers.tail.isEmpty) {
1247 error(call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER); 1255 error(call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER);
1248 } 1256 }
1249 // Check that there are no field initializing parameters. 1257 // Check that there are no field initializing parameters.
1250 Compiler compiler = visitor.compiler; 1258 Compiler compiler = visitor.compiler;
1251 FunctionSignature signature = constructor.computeSignature(compiler); 1259 FunctionSignature signature = constructor.computeSignature(compiler);
1252 signature.forEachParameter((Element parameter) { 1260 signature.forEachParameter((Element parameter) {
(...skipping 2861 matching lines...) Expand 10 before | Expand all | Expand 10 after
4114 return e; 4122 return e;
4115 } 4123 }
4116 4124
4117 /// Assumed to be called by [resolveRedirectingFactory]. 4125 /// Assumed to be called by [resolveRedirectingFactory].
4118 Element visitReturn(Return node) { 4126 Element visitReturn(Return node) {
4119 Node expression = node.expression; 4127 Node expression = node.expression;
4120 return finishConstructorReference(visit(expression), 4128 return finishConstructorReference(visit(expression),
4121 expression, expression); 4129 expression, expression);
4122 } 4130 }
4123 } 4131 }
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