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

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

Issue 23583035: Emit a compile-time error when returning a value from a constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Include howToFix and example in error message. 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
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 2505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 visitRethrow(Rethrow node) { 2516 visitRethrow(Rethrow node) {
2517 if (!inCatchBlock) { 2517 if (!inCatchBlock) {
2518 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); 2518 error(node, MessageKind.THROW_WITHOUT_EXPRESSION);
2519 } 2519 }
2520 } 2520 }
2521 2521
2522 visitReturn(Return node) { 2522 visitReturn(Return node) {
2523 if (node.isRedirectingFactoryBody) { 2523 if (node.isRedirectingFactoryBody) {
2524 handleRedirectingFactoryBody(node); 2524 handleRedirectingFactoryBody(node);
2525 } else { 2525 } else {
2526 Node expression = node.expression;
2527 if (expression != null &&
2528 enclosingElement.isGenerativeConstructor()) {
2529 // It is a compile-time error if a return statement of the form
2530 // `return e;` appears in a generative constructor. (Dart Language
2531 // Specification 13.12.)
2532 compiler.reportError(expression,
2533 MessageKind.CANNOT_RETURN_FROM_CONSTRUCTOR);
2534 }
2526 visit(node.expression); 2535 visit(node.expression);
2527 } 2536 }
2528 } 2537 }
2529 2538
2530 void handleRedirectingFactoryBody(Return node) { 2539 void handleRedirectingFactoryBody(Return node) {
2531 final isSymbolConstructor = enclosingElement == compiler.symbolConstructor; 2540 final isSymbolConstructor = enclosingElement == compiler.symbolConstructor;
2532 if (!enclosingElement.isFactoryConstructor()) { 2541 if (!enclosingElement.isFactoryConstructor()) {
2533 compiler.reportError( 2542 compiler.reportError(
2534 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY); 2543 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY);
2535 compiler.reportHint( 2544 compiler.reportHint(
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after
4105 return e; 4114 return e;
4106 } 4115 }
4107 4116
4108 /// Assumed to be called by [resolveRedirectingFactory]. 4117 /// Assumed to be called by [resolveRedirectingFactory].
4109 Element visitReturn(Return node) { 4118 Element visitReturn(Return node) {
4110 Node expression = node.expression; 4119 Node expression = node.expression;
4111 return finishConstructorReference(visit(expression), 4120 return finishConstructorReference(visit(expression),
4112 expression, expression); 4121 expression, expression);
4113 } 4122 }
4114 } 4123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698