Skip to content

fix(extract): prevent duplicate Function nodes for Java interface methods (#1234) - #1327

Open
harshitaajoshi wants to merge 3 commits into
DeusData:mainfrom
harshitaajoshi:fix/java-interface-duplicate-function-1234
Open

fix(extract): prevent duplicate Function nodes for Java interface methods (#1234)#1327
harshitaajoshi wants to merge 3 commits into
DeusData:mainfrom
harshitaajoshi:fix/java-interface-duplicate-function-1234

Conversation

@harshitaajoshi

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #1234.

Java interface methods were emitted as both a Method node (correct, via extract_class_methods) and a duplicate Function node (incorrect, via the walk_defs fallback). The root cause is that push_class_body_children() in extract_defs.c did not recognize interface_body as a class body container, even though find_class_body() already did. When the body type was unrecognized, the fallback path pushed all children (including method_declaration nodes) back onto the walk stack, where extract_func_def() minted a spurious Function node for each one.

This change adds interface_body and enum_body to the body container check in push_class_body_children(), consistent with find_class_body(). Both node types are used across multiple tree-sitter grammars (Java, TypeScript, Apex, Dart, and others).

A reproduce-first regression test verifies that a Java interface with two method declarations produces one Method node per method, zero Function nodes, and one Interface node for the type itself. The test fails without the fix (count_defs_with_label(r, "Function") == 2, expected 0) and passes with it.

Verification

  • build/c/test-runner extraction -- 254 passed
  • build/c/test-runner extraction extraction_inheritance extraction_imports pipeline registry grammar_labels grammar_regression -- 569 passed, 0 failed

Checklist

  • Every commit is signed off (git commit -s) -- required, CI rejects
    unsigned commits (DCO, see CONTRIBUTING.md)
  • Tests pass locally (make -f Makefile.cbm test)
    ASan hangs on macOS Tahoe 26.5 (Apple Clang 17) for any binary, including a trivial int main(){return 0;}. All 569 focused suite tests pass when built without sanitizers (SANITIZE="").
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)

…hods (DeusData#1234)

Signed-off-by: Harshita Joshi <j.harshitaa06@gmail.com>
@harshitaajoshi
harshitaajoshi requested a review from DeusData as a code owner July 29, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java: interface methods emitted twice — as both Method and Function nodes (472 spurious Function nodes)

1 participant