fix(dart): index a Dart 3 extension type as the type it is (#1784) (#1865)

`extension_type_declaration` appears in none of the three places Dart's other
type-like declarations do. `extension_declaration` — the older `extension` — is
in all three, and the two names are near neighbours.

That is why #1780's `isInsideClassLikeNode()` gate dropped these members and no
others: the gate asks whether a class-like node is on the stack, and an
`extension type` never put one there, while `extension`, `mixin` and `class`
all did. The gate surfaced the omission rather than causing it. Before it, the
members were still reached — but as top-level `function:km` rather than
`method:MetersT::km`, indexed and attributed to nothing.

The kernel omits the same node type, so it walks the members through its own
fallback and mints them as top-level functions with no `MetersT` to belong to.
`kernel-dart-parity.test.ts` fails four cases on `main` because of it; fixing
only the wasm side would leave those red.

Listing it alongside the others is the whole fix — `extraClassNodeTypes` and
`dartEnclosingTypeName` on the wasm side, the two `matches!` arms on the
kernel's. Both paths now give:

    class:MetersT · method:MetersT::km · method:MetersT::report

with `report`'s span running to its closing brace rather than stopping at the
signature line, and an ordinary class untouched.
This commit is contained in:
yucong-dong
2026-09-27 12:23:04 +00:00
committed by GitHub
parent cba44c9cad
commit 6f4ec88350
3 changed files with 74 additions and 5 deletions
+6 -2
View File
@@ -398,7 +398,7 @@ impl<'t> Walker<'t> {
while let Some(parent) = p {
if matches!(
parent.kind(),
"class_definition" | "mixin_declaration" | "extension_declaration" | "enum_declaration"
"class_definition" | "mixin_declaration" | "extension_declaration" | "extension_type_declaration" | "enum_declaration"
) {
return parent.child_by_field_name("name").map(|n| self.text(n));
}
@@ -630,7 +630,11 @@ impl<'t> Walker<'t> {
self.extract_function(node);
return;
}
"class_definition" | "mixin_declaration" | "extension_declaration" => {
// `extension_type_declaration` is Dart 3.3's extension type. It is a
// different node from `extension_declaration` above, which is the
// older `extension` — the names are near neighbours and only one of
// them was listed.
"class_definition" | "mixin_declaration" | "extension_declaration" | "extension_type_declaration" => {
self.extract_class(node);
return;
}