Skip to content

Commit cd5bcd7

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Fix for FieldFormalParameter with type parameters.
[email protected] Bug: #38057 Change-Id: I7a24adbc4af9c2e1bc244f0ebca1a651f2c487d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114929 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 6fa5b31 commit cd5bcd7

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,8 @@ class AstBinaryReader {
652652
),
653653
metadata: _readNodeList(data.normalFormalParameter_metadata),
654654
comment: _readDocumentationComment(data),
655-
type: _readNode(data.fieldFormalParameter_type),
656-
parameters: _readNode(data.fieldFormalParameter_formalParameters),
655+
type: _readNodeLazy(data.fieldFormalParameter_type),
656+
parameters: _readNodeLazy(data.fieldFormalParameter_formalParameters),
657657
requiredKeyword:
658658
AstBinaryFlags.isRequired(data.flags) ? _Tokens.REQUIRED : null,
659659
);

pkg/analyzer/lib/src/summary2/linked_unit_context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ class LinkedUnitContext {
647647
} else if (node is ExtensionDeclaration) {
648648
return node.typeParameters;
649649
} else if (node is FieldFormalParameter) {
650-
return null;
650+
return node.typeParameters;
651651
} else if (node is FunctionDeclaration) {
652652
LazyFunctionDeclaration.readFunctionExpression(_astReader, node);
653653
return getTypeParameters2(node.functionExpression);

pkg/analyzer/lib/src/summary2/reference_resolver.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,33 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
206206

207207
@override
208208
void visitFieldFormalParameter(FieldFormalParameter node) {
209+
var outerScope = scope;
210+
var outerReference = reference;
211+
212+
var name = node.identifier.name;
213+
reference = reference.getChild('@parameter').getChild(name);
214+
reference.node = node;
215+
216+
var element = ParameterElementImpl.forLinkedNode(
217+
outerReference.element,
218+
reference,
219+
node,
220+
);
221+
node.identifier.staticElement = element;
222+
_createTypeParameterElements(node.typeParameters);
223+
224+
scope = new EnclosedScope(scope);
225+
for (var typeParameter in element.typeParameters) {
226+
scope.define(typeParameter);
227+
}
228+
209229
node.type?.accept(this);
230+
node.typeParameters?.accept(this);
210231
node.parameters?.accept(this);
211232
nodesToBuildType.addDeclaration(node);
233+
234+
scope = outerScope;
235+
reference = outerReference;
212236
}
213237

214238
@override

pkg/analyzer/test/src/summary/resynthesize_ast_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class ApplyCheckElementTextReplacements {
3131
@reflectiveTest
3232
class ResynthesizeAstStrongTest extends ResynthesizeTestStrategyTwoPhase
3333
with ResynthesizeTestCases, GetElementTestCases, ResynthesizeTestHelpers {
34+
@override
35+
@failingTest
36+
test_class_constructor_field_formal_functionTyped_withReturnType_generic() async {
37+
await super
38+
.test_class_constructor_field_formal_functionTyped_withReturnType_generic();
39+
}
40+
3441
@failingTest // See dartbug.com/32290
3542
test_const_constructor_inferred_args() =>
3643
super.test_const_constructor_inferred_args();

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,21 @@ class C {
632632
''');
633633
}
634634

635+
test_class_constructor_field_formal_functionTyped_withReturnType_generic() async {
636+
var library = await checkLibrary(r'''
637+
class C {
638+
Function() f;
639+
C(List<U> this.f<T, U>(T t));
640+
}
641+
''');
642+
checkElementText(library, r'''
643+
class C {
644+
dynamic Function() f;
645+
C(List<U> Function<T, U>(T) this.f/*(T t)*/);
646+
}
647+
''');
648+
}
649+
635650
test_class_constructor_field_formal_multiple_matching_fields() async {
636651
// This is a compile-time error but it should still analyze consistently.
637652
var library = await checkLibrary('class C { C(this.x); int x; String x; }',

0 commit comments

Comments
 (0)