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

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: 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 2474 matching lines...) Expand 10 before | Expand all | Expand 10 after
2485 2485
2486 void handleRedirectingFactoryBody(Return node) { 2486 void handleRedirectingFactoryBody(Return node) {
2487 final isSymbolConstructor = enclosingElement == compiler.symbolConstructor; 2487 final isSymbolConstructor = enclosingElement == compiler.symbolConstructor;
2488 if (!enclosingElement.isFactoryConstructor()) { 2488 if (!enclosingElement.isFactoryConstructor()) {
2489 compiler.reportErrorCode( 2489 compiler.reportErrorCode(
2490 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY); 2490 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY);
2491 compiler.reportErrorCode( 2491 compiler.reportErrorCode(
2492 enclosingElement, MessageKind.MISSING_FACTORY_KEYWORD); 2492 enclosingElement, MessageKind.MISSING_FACTORY_KEYWORD);
2493 } 2493 }
2494 Element redirectionTarget = resolveRedirectingFactory(node); 2494 Element redirectionTarget = resolveRedirectingFactory(node);
2495 var type = mapping.getType(node.expression);
2496 if (type is InterfaceType && !type.isRaw) {
2497 unimplemented(node.expression, 'type arguments on redirecting factory');
2498 }
2499 useElement(node.expression, redirectionTarget); 2495 useElement(node.expression, redirectionTarget);
2500 FunctionElement constructor = enclosingElement; 2496 FunctionElement constructor = enclosingElement;
2501 if (constructor.modifiers.isConst() && 2497 if (constructor.modifiers.isConst() &&
2502 !redirectionTarget.modifiers.isConst()) { 2498 !redirectionTarget.modifiers.isConst()) {
2503 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); 2499 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
2504 } 2500 }
2505 constructor.defaultImplementation = redirectionTarget; 2501 constructor.defaultImplementation = redirectionTarget;
2506 if (Elements.isUnresolved(redirectionTarget)) return; 2502 if (Elements.isUnresolved(redirectionTarget) ||
2503 !redirectionTarget.isConstructor()) {
2504 compiler.backend.registerThrowNoSuchMethod(mapping);
ngeoffray 2013/05/30 08:23:14 Do you really need to make it explicit in both cas
karlklose 2013/05/30 11:44:23 The test is not necessary, I removed it.
2505 return;
2506 }
2507
2508 // Compute the signature of the target method taking into account the
2509 // type arguments that are specified in the redirection, and store it on
2510 // the return node.
2511 ClassElement targetClass = redirectionTarget.getEnclosingClass();
2512 InterfaceType type = mapping.getType(node.expression)
2513 .subst(currentClass.typeVariables, targetClass.typeVariables);
2514 mapping.setType(node, type);
2515
2516 // Check that the target constructor is type compatible with the
2517 // redirecting constructor.
2518 FunctionType targetType = redirectionTarget.computeType(compiler)
2519 .subst(type.typeArguments, targetClass.typeVariables);
2520 FunctionType constructorType = constructor.computeType(compiler);
2521 if (!compiler.types.isSubtype(targetType, constructorType)) {
2522 compiler.backend.registerThrowNoSuchMethod(mapping);
ngeoffray 2013/05/30 08:23:14 I think you can remove the registering here.
karlklose 2013/05/30 11:44:23 I have added logic to test whether we need this.
2523 warning(node, MessageKind.INVALID_ARGUMENTS,
2524 {'methodName': redirectionTarget.name});
2525 }
2507 2526
2508 // TODO(ahe): Check that this doesn't lead to a cycle. For now, 2527 // TODO(ahe): Check that this doesn't lead to a cycle. For now,
2509 // just make sure that the redirection target isn't itself a 2528 // just make sure that the redirection target isn't itself a
2510 // redirecting factory. 2529 // redirecting factory.
2511 { // This entire block is temporary code per the above TODO. 2530 { // This entire block is temporary code per the above TODO.
2512 FunctionElement targetImplementation = redirectionTarget.implementation; 2531 FunctionElement targetImplementation = redirectionTarget.implementation;
2513 FunctionExpression function = targetImplementation.parseNode(compiler); 2532 FunctionExpression function = targetImplementation.parseNode(compiler);
2514 if (function.body != null && function.body.asReturn() != null 2533 if (function.body != null && function.body.asReturn() != null
2515 && function.body.asReturn().isRedirectingFactoryBody) { 2534 && function.body.asReturn().isRedirectingFactoryBody) {
2516 unimplemented(node.expression, 'redirecing to redirecting factory'); 2535 unimplemented(node.expression, 'redirecting to redirecting factory');
2517 } 2536 }
2518 } 2537 }
2519 world.registerStaticUse(redirectionTarget); 2538 world.registerStaticUse(redirectionTarget);
2520 world.registerInstantiatedClass( 2539 world.registerInstantiatedClass(
2521 redirectionTarget.enclosingElement.declaration, mapping); 2540 redirectionTarget.enclosingElement.declaration, mapping);
2522 if (isSymbolConstructor) { 2541 if (isSymbolConstructor) {
2523 // Make sure that collection_dev.Symbol.validated is registered. 2542 // Make sure that collection_dev.Symbol.validated is registered.
2524 assert(invariant(node, compiler.symbolValidatedConstructor != null)); 2543 assert(invariant(node, compiler.symbolValidatedConstructor != null));
2525 world.registerStaticUse(compiler.symbolValidatedConstructor); 2544 world.registerStaticUse(compiler.symbolValidatedConstructor);
2526 } 2545 }
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3990 return e; 4009 return e;
3991 } 4010 }
3992 4011
3993 /// Assumed to be called by [resolveRedirectingFactory]. 4012 /// Assumed to be called by [resolveRedirectingFactory].
3994 Element visitReturn(Return node) { 4013 Element visitReturn(Return node) {
3995 Node expression = node.expression; 4014 Node expression = node.expression;
3996 return finishConstructorReference(visit(expression), 4015 return finishConstructorReference(visit(expression),
3997 expression, expression); 4016 expression, expression);
3998 } 4017 }
3999 } 4018 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698