fix(extract): scan every attribute_list sibling, not just the first (#1692) - #1759
Open
Jumaga2015 wants to merge 2 commits into
Open
fix(extract): scan every attribute_list sibling, not just the first (#1692)#1759Jumaga2015 wants to merge 2 commits into
Jumaga2015 wants to merge 2 commits into
Conversation
A C# attribute stack ([Foo][Bar][Baz]) compiles to separate sibling attribute_list nodes, one per bracket group — not one attribute_list holding several entries. find_jvm_modifiers() used ts_node_child_by_field_name(), which only ever returns the first child registered under a given field, so every attribute after the first bracket group was silently dropped and never produced a DECORATES edge (DeusData#1692). find_jvm_modifiers() now returns every matching wrapper (count + out array, capped at MAX_ATTR_WRAPPERS) instead of a single TSNode, and its two callers (extract_decorators, scan_route_annotations) iterate all of them. The multi-match child scan lives in a new helper, cbm_find_children_by_kind() (helpers.c/helpers.h), the multi-match sibling of the existing cbm_find_child_by_kind() — keeps find_jvm_modifiers() a short per-language dispatch that delegates the traversal, same shape it had before this fix. Both callers size `wrappers` at MAX_ATTR_WRAPPERS. scan_route_annotations appends the owner node after the wrappers, so its fill is capped one lower (MAX_ATTR_WRAPPERS_MINUS_1) rather than the array being declared one larger — the MAX_X / MAX_X_MINUS_1 pair this file already uses for MAX_BASES, MAX_PARAMS and MAX_RETURN_TYPES. No-op for the other languages on this switch: Java/Kotlin/Swift use the `modifiers` wrapper, a single node that never repeats, and PHP groups a `#[A] #[B] #[C]` stack under ONE attribute_list holding three attribute_group children, which the previous lookup already returned whole. Signed-off-by: Jumaga2015 <jumaga2015@gmail.com>
A C# method carrying three stacked attributes ([Foo][Bar("x")][Baz]) must
end up with three DECORATES edges, one per bracket group. The fixture is
indexed through the real production pipeline (rh_index) and asserts
rh_count_edges(..., "DECORATES") == 3, so it exercises the MCP path rather
than the extractor in isolation.
Verified to actually reproduce: with find_jvm_modifiers() reverted to its
first-child lookup the suite goes red (decorates=1, expected 3), and green
again with the fix in place.
C#-only by design. Parsing the equivalent fixtures with the vendored
grammars shows `[A] [B] [C]` yields three sibling `attribute_list` nodes in
C#, while PHP's `#[A] #[B] #[C]` yields ONE `attribute_list` holding three
`attribute_group` children — the pre-fix lookup already found all of them,
so PHP could not hit this bug and a stacked-PHP fixture would pass either
way. Java/Kotlin/Swift use the `modifiers` wrapper, a single node that never
repeats. PHP's DECORATES path stays covered by mkc_c3_php8_attribute
(tests/test_matrix_known_classes.c).
Registered in repro_main.c and Makefile.cbm's TEST_REPRO_SRCS.
Signed-off-by: Jumaga2015 <jumaga2015@gmail.com>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
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.
Summary
misclassification half, which is a separate call-resolution defect left
for its own atomic fix as requested in the issue thread): a C# method or
class with 2+ stacked attributes only got a
DECORATESedge for thefirst bracket group.
find_jvm_modifiers()usedts_node_child_by_field_name(), which returns only the first matchingchild, so a route attribute stacked behind another one (e.g.
[ServiceFilter(...)]then[Route("api/[controller]")]) was silentlyinvisible to
references/symbolsand to route extraction.find_jvm_modifiers()now returns every matching wrapper via a newcbm_find_children_by_kind()helper; both callers (extract_decorators,scan_route_annotations) iterate all of them.modifierswrapper (never repeats);PHP already groups a stack under one
attribute_list.Test plan
repro_issue1692(Makefile.cbmTEST_REPRO_SRCS) — indexes[Foo][Bar("x")][Baz]through the real production pipeline andasserts
DECORATES== 3. Proven RED with the pre-fix lookup(decorates=1), GREEN with the fix.
scripts/test.sh CC=clang CXX=clang++— full suite, no regressionsscripts/lint.sh CC=clang CXX=clang++— clang-tidy (diff-scoped),clang-format, cppcheck all clean
Made with Claude Code