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

Unified 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 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 aca4608e3a976031939e4b2b60844cf9b84ffe5c..64593e7a1c5babdbf71b61221f43ce56faacaf3c 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -361,11 +361,17 @@ class ResolverTask extends CompilerTask {
error(tree, MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
return;
}
- if (isConstructor) {
+ if (isConstructor || element.isFactoryConstructor()) {
if (tree.returnType != null) {
error(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE);
}
+ if (element.modifiers.isConst() &&
+ tree.hasBody() &&
+ !tree.isRedirectingFactory) {
+ compiler.reportError(tree, MessageKind.CONST_CONSTRUCTOR_HAS_BODY);
+ }
}
+
ResolverVisitor visitor = visitorFor(element);
visitor.useElement(tree, element);
visitor.setupFunction(tree, element);
@@ -1238,8 +1244,10 @@ class InitializerResolver {
resolveSuperOrThisForSend(constructor, functionNode, call);
resolvedSuper = true;
} else if (Initializers.isConstructorRedirect(call)) {
- // Check that there is no body (Language specification 7.5.1).
- if (functionNode.hasBody()) {
+ // Check that there is no body (Language specification 7.5.1). If the
+ // constructor is also const, we already reported an error in
+ // [resolveMethodElement].
+ if (functionNode.hasBody() && !constructor.modifiers.isConst()) {
error(functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY);
}
// Check that there are no other initializers.
« 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