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

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

Issue 12093019: Support type variables on redirecting factory constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 6 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 2482 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 2493
2494 void handleRedirectingFactoryBody(Return node) { 2494 void handleRedirectingFactoryBody(Return node) {
2495 final isSymbolConstructor = enclosingElement == compiler.symbolConstructor; 2495 final isSymbolConstructor = enclosingElement == compiler.symbolConstructor;
2496 if (!enclosingElement.isFactoryConstructor()) { 2496 if (!enclosingElement.isFactoryConstructor()) {
2497 compiler.reportErrorCode( 2497 compiler.reportErrorCode(
2498 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY); 2498 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY);
2499 compiler.reportErrorCode( 2499 compiler.reportErrorCode(
2500 enclosingElement, MessageKind.MISSING_FACTORY_KEYWORD); 2500 enclosingElement, MessageKind.MISSING_FACTORY_KEYWORD);
2501 } 2501 }
2502 Element redirectionTarget = resolveRedirectingFactory(node); 2502 Element redirectionTarget = resolveRedirectingFactory(node);
2503 var type = mapping.getType(node.expression);
2504 if (type is InterfaceType && !type.isRaw) {
2505 unimplemented(node.expression, 'type arguments on redirecting factory');
2506 }
2507 useElement(node.expression, redirectionTarget); 2503 useElement(node.expression, redirectionTarget);
2508 FunctionElement constructor = enclosingElement; 2504 FunctionElement constructor = enclosingElement;
2509 if (constructor.modifiers.isConst() && 2505 if (constructor.modifiers.isConst() &&
2510 !redirectionTarget.modifiers.isConst()) { 2506 !redirectionTarget.modifiers.isConst()) {
2511 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); 2507 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
2512 } 2508 }
2513 constructor.defaultImplementation = redirectionTarget; 2509 constructor.defaultImplementation = redirectionTarget;
2514 if (Elements.isUnresolved(redirectionTarget)) return; 2510 if (Elements.isUnresolved(redirectionTarget)) {
2511 compiler.backend.registerThrowNoSuchMethod(mapping);
2512 return;
2513 }
2514
2515 // Compute the signature of the target method taking into account the
2516 // type arguments that are specified in the redirection, and store it on
2517 // the return node.
2518 ClassElement targetClass = redirectionTarget.getEnclosingClass();
2519 InterfaceType type = mapping.getType(node.expression)
2520 .subst(currentClass.typeVariables, targetClass.typeVariables);
2521 mapping.setType(node, type);
2522
2523 // Check that the target constructor is type compatible with the
2524 // redirecting constructor.
2525 FunctionType targetType = redirectionTarget.computeType(compiler)
2526 .subst(type.typeArguments, targetClass.typeVariables);
2527 FunctionType constructorType = constructor.computeType(compiler);
2528 if (!compiler.types.isSubtype(targetType, constructorType)) {
2529 warning(node, MessageKind.NOT_ASSIGNABLE,
2530 {'fromType': targetType, 'toType': constructorType});
2531 }
2532
2533 FunctionSignature targetSignature =
2534 redirectionTarget.computeSignature(compiler);
2535 FunctionSignature constructorSignature =
2536 constructor.computeSignature(compiler);
2537 if (!targetSignature.isCompatibleWith(constructorSignature)) {
2538 compiler.backend.registerThrowNoSuchMethod(mapping);
2539 }
2515 2540
2516 // TODO(ahe): Check that this doesn't lead to a cycle. For now, 2541 // TODO(ahe): Check that this doesn't lead to a cycle. For now,
2517 // just make sure that the redirection target isn't itself a 2542 // just make sure that the redirection target isn't itself a
2518 // redirecting factory. 2543 // redirecting factory.
2519 { // This entire block is temporary code per the above TODO. 2544 { // This entire block is temporary code per the above TODO.
2520 FunctionElement targetImplementation = redirectionTarget.implementation; 2545 FunctionElement targetImplementation = redirectionTarget.implementation;
2521 FunctionExpression function = targetImplementation.parseNode(compiler); 2546 FunctionExpression function = targetImplementation.parseNode(compiler);
2522 if (function.body != null && function.body.asReturn() != null 2547 if (function.body != null && function.body.asReturn() != null
2523 && function.body.asReturn().isRedirectingFactoryBody) { 2548 && function.body.asReturn().isRedirectingFactoryBody) {
2524 unimplemented(node.expression, 'redirecing to redirecting factory'); 2549 unimplemented(node.expression, 'redirecting to redirecting factory');
2525 } 2550 }
2526 } 2551 }
2527 world.registerStaticUse(redirectionTarget); 2552 world.registerStaticUse(redirectionTarget);
2528 world.registerInstantiatedClass( 2553 world.registerInstantiatedClass(
2529 redirectionTarget.enclosingElement.declaration, mapping); 2554 redirectionTarget.enclosingElement.declaration, mapping);
2530 if (isSymbolConstructor) { 2555 if (isSymbolConstructor) {
2531 // Make sure that collection_dev.Symbol.validated is registered. 2556 // Make sure that collection_dev.Symbol.validated is registered.
2532 assert(invariant(node, compiler.symbolValidatedConstructor != null)); 2557 assert(invariant(node, compiler.symbolValidatedConstructor != null));
2533 world.registerStaticUse(compiler.symbolValidatedConstructor); 2558 world.registerStaticUse(compiler.symbolValidatedConstructor);
2534 } 2559 }
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3998 return e; 4023 return e;
3999 } 4024 }
4000 4025
4001 /// Assumed to be called by [resolveRedirectingFactory]. 4026 /// Assumed to be called by [resolveRedirectingFactory].
4002 Element visitReturn(Return node) { 4027 Element visitReturn(Return node) {
4003 Node expression = node.expression; 4028 Node expression = node.expression;
4004 return finishConstructorReference(visit(expression), 4029 return finishConstructorReference(visit(expression),
4005 expression, expression); 4030 expression, expression);
4006 } 4031 }
4007 } 4032 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698