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

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: Address comments. 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 b9ee92552b1812f06ac4140d5a009f24df7d49d7..b44df2b079fd29ec8d97882eeaf65f72a8769af2 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -3378,6 +3378,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
FunctionElement functionElement = constructor;
constructor = functionElement.redirectionTarget;
+
final bool isSymbolConstructor =
functionElement == compiler.symbolConstructor;
@@ -3390,6 +3391,23 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
message: 'Constructor Symbol.validated is missing'));
}
+ bool isRedirected = functionElement.isRedirectingFactory;
+ 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;
+ }
+
var inputs = <HInstruction>[];
// TODO(5347): Try to avoid the need for calling [implementation] before
// calling [addStaticSendArgumentsToList].
@@ -3434,6 +3452,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