fix(extract): prevent duplicate Function nodes for Java interface methods (#1234) - #1327
Open
harshitaajoshi wants to merge 3 commits into
Open
Conversation
…hods (DeusData#1234) Signed-off-by: Harshita Joshi <j.harshitaa06@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thewalk_defsfallback). The root cause is thatpush_class_body_children()inextract_defs.cdid not recognizeinterface_bodyas a class body container, even thoughfind_class_body()already did. When the body type was unrecognized, the fallback path pushed all children (includingmethod_declarationnodes) back onto the walk stack, whereextract_func_def()minted a spurious Function node for each one.This change adds
interface_bodyandenum_bodyto the body container check inpush_class_body_children(), consistent withfind_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 passedbuild/c/test-runner extraction extraction_inheritance extraction_imports pipeline registry grammar_labels grammar_regression-- 569 passed, 0 failedChecklist
git commit -s) -- required, CI rejectsunsigned commits (DCO, see CONTRIBUTING.md)
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="").make -f Makefile.cbm lint-ci)