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

Unified Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 18181009: Make closures in constructor initializers read type variables directly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add VM crash and modify test. 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 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 a73f41c2fa0c759ad521fb37dd99ede95fef44e7..ab3d5038d3fe6eb95790e449824c47dbace95484 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -3276,6 +3276,14 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
return pop();
}
+ // TODO(karlklose): this is needed to avoid a bug where the resolved type is
+ // not stored on a type annotation in the closure translator. Remove when
ngeoffray 2013/07/12 12:09:25 Not sure I understand this comment. What does it m
karlklose 2013/07/12 12:22:54 The wording isn't the best, I agree. With storing
ngeoffray 2013/07/12 12:27:39 So that's a bug in the resolver?
+ // fixed.
+ bool hasDirectLocal(Element element) {
+ return !localsHandler.isAccessedDirectly(element) ||
+ localsHandler.directLocals[element] != null;
+ }
+
/**
* Helper to create an instruction that gets the value of a type variable.
*/
@@ -3288,10 +3296,10 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
member = member.getOutermostEnclosingMemberOrTopLevel();
}
bool isInConstructorContext = member.isConstructor() ||
- member.isGenerativeConstructorBody() ||
- member.isField();
+ member.isGenerativeConstructorBody();
if (isClosure) {
- if (member.isFactoryConstructor()) {
+ if (member.isFactoryConstructor() ||
+ (isInConstructorContext && hasDirectLocal(type.element))) {
// The type variable is used from a closure in a factory constructor.
// The value of the type argument is stored as a local on the closure
// itself.
@@ -3299,8 +3307,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
} else if (member.isFunction() ||
member.isGetter() ||
member.isSetter() ||
- member.isConstructor() ||
- member.isGenerativeConstructorBody()) {
+ isInConstructorContext) {
// The type variable is stored on the "enclosing object" and needs to be
// accessed using the this-reference in the closure.
return readTypeVariable(member.getEnclosingClass(), type.element);
@@ -3309,7 +3316,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
// The type variable is stored in a parameter of the method.
return localsHandler.readLocal(type.element);
}
- } else if (isInConstructorContext) {
+ } else if (isInConstructorContext || member.isField()) {
// The type variable is stored in a parameter of the method.
return localsHandler.readLocal(type.element);
} else if (member.isInstanceMember()) {
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/closure.dart ('k') | tests/language/closure_in_constructor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698