Skip to content

Commit 3417d1a

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Fix for lazy loading methods.
Bug: https://buganizer.corp.google.com/issues/389978393 Change-Id: I9693b77e5e67b53b5be8c0eb4bc4aafb5f7a27cd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404502 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 9e8e8e5 commit 3417d1a

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5695,8 +5695,7 @@ abstract class InstanceElementImpl2 extends ElementImpl2
56955695
@override
56965696
List<MethodElement> methods = [];
56975697

5698-
@override
5699-
List<MethodElementImpl2> methods2 = [];
5698+
final List<MethodElementImpl2> internal_methods2 = [];
57005699

57015700
@override
57025701
InstanceElement2 get baseElement => this;
@@ -5766,6 +5765,12 @@ abstract class InstanceElementImpl2 extends ElementImpl2
57665765
@override
57675766
Metadata get metadata2 => firstFragment.metadata2;
57685767

5768+
@override
5769+
List<MethodElementImpl2> get methods2 {
5770+
_readMembers();
5771+
return internal_methods2;
5772+
}
5773+
57695774
@override
57705775
String? get name3 => firstFragment.name;
57715776

@@ -6522,7 +6527,7 @@ abstract class InterfaceElementImpl2 extends InstanceElementImpl2
65226527

65236528
@override
65246529
List<ConstructorElement2> get constructors2 {
6525-
firstFragment.constructors; // TODO(scheglov): remove eventually
6530+
_readMembers();
65266531
return constructors
65276532
.map((constructor) =>
65286533
(constructor.declaration as ConstructorElementImpl).element)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ class LibraryReader {
13791379
fragment.element = element;
13801380
} else {
13811381
var element = MethodElementImpl2(reference2, fragment.name2, fragment);
1382-
_currentInstanceElement.methods2.add(element);
1382+
_currentInstanceElement.internal_methods2.add(element);
13831383
}
13841384

13851385
var linkedData = MethodElementLinkedData(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
12551255
fragment.name2,
12561256
fragment,
12571257
);
1258-
enclosingBuilder.element.methods2.add(element);
1258+
enclosingBuilder.element.internal_methods2.add(element);
12591259
}
12601260
}
12611261
}

pkg/analyzer/test/src/summary/elements/class_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18432,6 +18432,61 @@ library
1843218432
''');
1843318433
}
1843418434

18435+
test_class_lazy_constructors() async {
18436+
var library = await buildLibrary('''
18437+
class A {
18438+
A.named();
18439+
}
18440+
''');
18441+
18442+
var constructors = library.getClass2('A')!.constructors2;
18443+
expect(constructors, hasLength(1));
18444+
}
18445+
18446+
test_class_lazy_fields() async {
18447+
var library = await buildLibrary('''
18448+
class A {
18449+
int foo = 0;
18450+
}
18451+
''');
18452+
18453+
var fields = library.getClass2('A')!.fields2;
18454+
expect(fields, hasLength(1));
18455+
}
18456+
18457+
test_class_lazy_getters() async {
18458+
var library = await buildLibrary('''
18459+
class A {
18460+
int foo = 0;
18461+
}
18462+
''');
18463+
18464+
var getters = library.getClass2('A')!.getters2;
18465+
expect(getters, hasLength(1));
18466+
}
18467+
18468+
test_class_lazy_methods() async {
18469+
var library = await buildLibrary('''
18470+
class A {
18471+
void foo() {}
18472+
}
18473+
''');
18474+
18475+
var methods = library.getClass2('A')!.methods2;
18476+
expect(methods, hasLength(1));
18477+
}
18478+
18479+
test_class_lazy_setters() async {
18480+
var library = await buildLibrary('''
18481+
class A {
18482+
int foo = 0;
18483+
}
18484+
''');
18485+
18486+
var setters = library.getClass2('A')!.setters2;
18487+
expect(setters, hasLength(1));
18488+
}
18489+
1843518490
test_class_method_abstract() async {
1843618491
var library = await buildLibrary('abstract class C { f(); }');
1843718492
checkElementText(library, r'''

0 commit comments

Comments
 (0)