Chromium Code Reviews| 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); |
| } |