Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2edc9f4

Browse files
committed
Issue 211853720. Link default constructors to their references.
Bug: https://buganizer.corp.google.com/issues/211853720 Change-Id: I07a2fbce46ca5f2901e043f80b9f24efe9fe6e43 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/225621 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 6e27367 commit 2edc9f4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -957,15 +957,14 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
957957
element.fields = holder.properties.whereType<FieldElement>().toList();
958958
element.methods = holder.methods;
959959

960-
var constructors = holder.constructors;
961-
if (constructors.isEmpty) {
962-
var containerRef = element.reference!.getChild('@constructor');
963-
constructors = [
964-
ConstructorElementImpl('', -1)
965-
..isSynthetic = true
966-
..reference = containerRef.getChild(''),
967-
];
960+
if (holder.constructors.isEmpty) {
961+
holder.addConstructor(
962+
'',
963+
ConstructorElementImpl('', -1)..isSynthetic = true,
964+
);
968965
}
966+
967+
var constructors = holder.constructors;
969968
element.constructors = constructors;
970969

971970
// We have all fields and constructors.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,19 @@ class _ElementWriter {
355355
void _writeConstructorElement(ConstructorElement e) {
356356
e as ConstructorElementImpl;
357357

358+
// Check that the reference exists, and filled with the element.
359+
var reference = e.reference;
360+
if (reference == null) {
361+
fail('Every constructor must have a reference.');
362+
} else {
363+
var classReference = reference.parent!.parent!;
364+
// We need this `if` for duplicate declarations.
365+
// The reference might be filled by another declaration.
366+
if (identical(classReference.element, e.enclosingElement)) {
367+
expect(reference.element, same(e));
368+
}
369+
}
370+
358371
_writeIndentedLine(() {
359372
_writeIf(e.isSynthetic, 'synthetic ');
360373
_writeIf(e.isExternal, 'external ');

0 commit comments

Comments
 (0)