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

Unified Diff: pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Issue 2363503003: fix #27411, avoid capture for instance creation (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index fafb7b9c9fae82ca2a3c71923da080b006e36fc6..2bd7f366defad1c9b5b82cd43042892e32c5ce0b 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -1602,10 +1602,37 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
return type;
}
- FunctionElementImpl function = new FunctionElementImpl("", -1);
+ // TODO(jmesserly): feels like we should be able to do this with less code.
+
+ // Create fresh type formals. This avoids capture if we're inferring the
+ // constructor to the class from inside it.
+
+ // We build up a substitution for the type parameters,
+ // {variablesFresh/variables} they apply it.
Leaf 2016/09/21 23:12:58 s/they/then/ ?
Jennifer Messerly 2016/09/21 23:19:54 Done.
+ var typeVars = <DartType>[];
+ var freshTypeVars = <DartType>[];
+ var freshVarElements = <TypeParameterElement>[];
+ for (int i = 0; i < cls.typeParameters.length; i++) {
+ var typeParamElement = cls.typeParameters[i];
+ var freshElement =
+ new TypeParameterElementImpl.synthetic(typeParamElement.name);
+ var freshTypeVar = new TypeParameterTypeImpl(freshElement);
+ freshElement.type = freshTypeVar;
+
+ typeVars.add(typeParamElement.type);
+ freshTypeVars.add(freshTypeVar);
+ freshVarElements.add(freshElement);
+
+ var bound = typeParamElement.bound ?? DynamicTypeImpl.instance;
+ freshElement.bound = bound.substitute2(freshTypeVars, typeVars);
+ }
+
+ type = type.substitute2(freshTypeVars, typeVars);
+
+ var function = new FunctionElementImpl("", -1);
function.synthetic = true;
function.returnType = type.returnType;
- function.shareTypeParameters(cls.typeParameters);
+ function.typeParameters = freshVarElements;
function.shareParameters(type.parameters);
return function.type = new FunctionTypeImpl(function);
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698