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

Unified Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.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, 7 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
Index: sdk/lib/_internal/compiler/implementation/ssa/builder.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
index 11146ddc8af0608bc83f9d347b4cd6e793bd0c8b..e035636619b1b7ecc55e52e4659d4f97f02cbeb0 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -3369,6 +3369,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
FunctionElement functionElement = constructor;
constructor = functionElement.redirectionTarget;
+
final bool isSymbolConstructor =
functionElement == compiler.symbolConstructor;
@@ -3381,6 +3382,26 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
message: 'Constructor Symbol.validated is missing'));
}
+ bool isRedirected = functionElement.redirectionTarget != functionElement;
ngeoffray 2013/05/30 08:23:14 Add this logic to the FunctionElement class or Ele
karlklose 2013/05/30 11:44:23 Done.
+ DartType expectedType = type;
+ if (isRedirected) {
+ FunctionExpression functionNode = functionElement.parseNode(compiler);
+ if (functionNode.isRedirectingFactory) {
+ // Lookup the type used in the redirection.
+ Return redirectionNode = functionNode.body;
+ TreeElements treeElements =
+ compiler.enqueuer.resolution.getCachedElements(
+ functionElement.declaration);
+ ClassElement targetClass = functionElement.getEnclosingClass();
+ type = treeElements.getType(redirectionNode)
+ .subst(type.typeArguments, targetClass.typeVariables);
+ }
+ functionElement = functionElement.redirectionTarget;
+ }
+
+ // TODO(karlklose): move this type registration to the codegen.
+ compiler.codegenWorld.instantiatedTypes.add(type);
ngeoffray 2013/05/30 08:23:14 Why is that needed here now, even in the case it's
karlklose 2013/05/30 11:44:23 This was a leftover from the old state of the buil
+
var inputs = <HInstruction>[];
// TODO(5347): Try to avoid the need for calling [implementation] before
// calling [addStaticSendArgumentsToList].
@@ -3425,6 +3446,15 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
if (isListConstructor && backend.needsRti(compiler.listClass)) {
handleListConstructor(type, send, newInstance);
}
+
+ // Finally, if we called a redirecting factory constructor, check the type.
+ if (isRedirected) {
+ HInstruction checked = potentiallyCheckType(newInstance, expectedType);
+ if (checked != newInstance) {
+ pop();
+ stack.add(checked);
+ }
+ }
}
visitStaticSend(Send node) {

Powered by Google App Engine
This is Rietveld 408576698