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

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

Issue 11365108: Implement redirecting constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 8 years, 1 month 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
Index: dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
index 9342f47fa70aea1a121d9eda5288b83b1db38d7d..a221d65a15818f2784ce8b89ddb3d531a09446db 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -1870,12 +1870,40 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
visitReturn(Return node) {
if (node.isRedirectingFactoryBody) {
- useElement(node.expression, resolveRedirectingFactory(node));
+ handleRedirectingFactoryBody(node);
} else {
visit(node.expression);
}
}
+ void handleRedirectingFactoryBody(Return node) {
+ Element redirectionTarget = resolveRedirectingFactory(node);
+ var type = mapping.getType(node.expression);
+ if (type is InterfaceType && !type.arguments.isEmpty) {
+ unimplemented(node.expression, 'type arguments on redirecting factory');
+ }
+ useElement(node.expression, redirectionTarget);
+ assert(invariant(node, enclosingElement.isFactoryConstructor()));
+ FunctionElement constructor = enclosingElement;
+ if (constructor.modifiers.isConst() &&
+ !redirectionTarget.modifiers.isConst()) {
+ error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
+ }
+ // TODO(ahe): Check that this doesn't lead to a cycle. For now,
+ // just make sure that the redirection target isn't itself a
+ // redirecting factory.
+ { // This entire block is temporary code per the above TODO.
+ FunctionElement targetImplementation = redirectionTarget.implementation;
+ FunctionExpression function = targetImplementation.parseNode(compiler);
+ if (function.body != null && function.body.asReturn() != null
+ && function.body.asReturn().isRedirectingFactoryBody) {
+ unimplemented(node.expression, 'redirecing to redirecting factory');
+ }
+ }
+ constructor.defaultImplementation = redirectionTarget;
+ world.registerStaticUse(redirectionTarget);
+ }
+
visitThrow(Throw node) {
if (!inCatchBlock && node.expression == null) {
error(node, MessageKind.THROW_WITHOUT_EXPRESSION);

Powered by Google App Engine
This is Rietveld 408576698