Skip to content

Commit ee89054

Browse files
committed
Issue 29288. When infer new FunctionType, makes its FunctionElement own its ParameterElement(s).
Never share. [email protected] BUG= #29288 Review-Url: https://codereview.chromium.org/2799093007 .
1 parent 1910147 commit ee89054

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

pkg/analyzer/lib/src/generated/type_system.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,8 @@ class StrongTypeSystemImpl extends TypeSystem {
622622
// Also pass dynamicIsBottom, because this is a fuzzy arrow.
623623
var newType = _substituteForUnknownType(p.type,
624624
lowerBound: !lowerBound, dynamicIsBottom: true);
625-
return identical(p.type, newType) && p is ParameterElementImpl
626-
? p
627-
: new ParameterElementImpl.synthetic(
628-
p.name, newType, p.parameterKind);
625+
return new ParameterElementImpl.synthetic(
626+
p.name, newType, p.parameterKind);
629627
});
630628
// Return type is covariant.
631629
var newReturnType =
@@ -639,7 +637,7 @@ class StrongTypeSystemImpl extends TypeSystem {
639637
..isSynthetic = true
640638
..returnType = newReturnType
641639
..shareTypeParameters(type.typeFormals)
642-
..shareParameters(newParameters);
640+
..parameters = newParameters;
643641
return function.type = new FunctionTypeImpl(function);
644642
}
645643
return type;

pkg/analyzer/test/generated/strong_mode_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,6 +3154,30 @@ void test() {
31543154
expectIdentifierType('cc', "C<int, B<int>, A<dynamic>>");
31553155
}
31563156

3157+
test_inferClosureType_parameters() async {
3158+
Source source = addSource(r'''
3159+
typedef F({bool p});
3160+
foo(callback(F f)) {}
3161+
main() {
3162+
foo((f) {
3163+
f(p: false);
3164+
});
3165+
}
3166+
''');
3167+
var result = await computeAnalysisResult(source);
3168+
var main = result.unit.declarations[2] as FunctionDeclaration;
3169+
var body = main.functionExpression.body as BlockFunctionBody;
3170+
var statement = body.block.statements[0] as ExpressionStatement;
3171+
var invocation = statement.expression as MethodInvocation;
3172+
var closure = invocation.argumentList.arguments[0] as FunctionExpression;
3173+
var closureType = closure.staticType as FunctionType;
3174+
var fType = closureType.parameters[0].type as FunctionType;
3175+
// The inferred type of "f" in "foo()" invocation must own its parameters.
3176+
ParameterElement p = fType.parameters[0];
3177+
expect(p.name, 'p');
3178+
expect(p.enclosingElement, same(fType.element));
3179+
}
3180+
31573181
@failingTest
31583182
test_instantiateToBounds_class_error_extension_malbounded() async {
31593183
// Test that superclasses are strictly checked for malbounded default

0 commit comments

Comments
 (0)