Issue 29288. When infer new FunctionType, makes its FunctionElement own its ParameterElement(s).

Never share.

R=brianwilkerson@google.com
BUG= https://github.com/dart-lang/sdk/issues/29288

Review-Url: https://codereview.chromium.org/2799093007 .
This commit is contained in:
Konstantin Shcheglov 2017-04-07 12:21:51 -07:00
parent 1910147425
commit ee89054fe9
2 changed files with 27 additions and 5 deletions

View file

@ -622,10 +622,8 @@ class StrongTypeSystemImpl extends TypeSystem {
// Also pass dynamicIsBottom, because this is a fuzzy arrow.
var newType = _substituteForUnknownType(p.type,
lowerBound: !lowerBound, dynamicIsBottom: true);
return identical(p.type, newType) && p is ParameterElementImpl
? p
: new ParameterElementImpl.synthetic(
p.name, newType, p.parameterKind);
return new ParameterElementImpl.synthetic(
p.name, newType, p.parameterKind);
});
// Return type is covariant.
var newReturnType =
@ -639,7 +637,7 @@ class StrongTypeSystemImpl extends TypeSystem {
..isSynthetic = true
..returnType = newReturnType
..shareTypeParameters(type.typeFormals)
..shareParameters(newParameters);
..parameters = newParameters;
return function.type = new FunctionTypeImpl(function);
}
return type;

View file

@ -3154,6 +3154,30 @@ void test() {
expectIdentifierType('cc', "C<int, B<int>, A<dynamic>>");
}
test_inferClosureType_parameters() async {
Source source = addSource(r'''
typedef F({bool p});
foo(callback(F f)) {}
main() {
foo((f) {
f(p: false);
});
}
''');
var result = await computeAnalysisResult(source);
var main = result.unit.declarations[2] as FunctionDeclaration;
var body = main.functionExpression.body as BlockFunctionBody;
var statement = body.block.statements[0] as ExpressionStatement;
var invocation = statement.expression as MethodInvocation;
var closure = invocation.argumentList.arguments[0] as FunctionExpression;
var closureType = closure.staticType as FunctionType;
var fType = closureType.parameters[0].type as FunctionType;
// The inferred type of "f" in "foo()" invocation must own its parameters.
ParameterElement p = fType.parameters[0];
expect(p.name, 'p');
expect(p.enclosingElement, same(fType.element));
}
@failingTest
test_instantiateToBounds_class_error_extension_malbounded() async {
// Test that superclasses are strictly checked for malbounded default