Repository navigation
fix(objective-c): recover bodyless C-style prototypes in func_start - #1357
Merged
Merged
Conversation
…1336) The C-style prototype alternative of objc's func_start regex (e.g. `extern void write_rtf_header(NXStream* rtfStream);`) was left brace-only when #1332 fixed the sibling `-`/`+` method alternative, since it had no exclusion shield and could already match a bare two-token call/return statement (`return foo(x);`). Real prototypes were only ever found by accident when a `{` happened to appear later in the search window, and grabbed whatever unrelated `{...}` block was nearest (in the corpus case, an `@interface` block's own ivar list several lines later) as a bogus body. Fix: add a "not a function" keyword shield (mirroring `branch`'s own control-flow keyword set) to the regex, closing off the bare-statement false-positive class outright. With that shield in place, detector.py can safely accept a bare `;` terminator for this alternative too, the same way #1332 did for the method alternative. Verified against language-crucible/data/objective-c/worldwideweb/HyperText.h: write_rtf_header now correctly spans just its own line (was lines 19-30, stealing the @interface block's ivar list). Golden masters re-blessed: +1 real prototype recovered in HyperText.h, and 2 latent `return foo();` false positives removed from HyperText.m (HTStyleForRun, HTSave) that this same shield closes off as a side effect. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
…pting them The previous commit accepted a bare `;` terminator for the C-style prototype alternative (mirroring #1332's fix for the `-`/`+` method alternative), recovering prototypes like `extern void write_rtf_header(...)` as func_start matches. tree-sitter-accuracy-audit flagged this as a regression: tree-sitter's own C/objc grammar parses a bodyless prototype as a `declaration` node, not `function_definition` -- the ground truth this repo measures against never counted prototypes as real functions, since they have no executable logic to score in the first place. Reworked to the issue's own suggested alternative: explicitly exclude bodyless C-style prototypes from func_start's scope, rather than trying to recover them. This still fixes the original bug (a real prototype previously found only by accident, with a bogus body span stolen from unrelated nearby code) -- it's now correctly never matched at all, instead of sometimes matched with a wrong body. Real C-style function *definitions* (with an actual `{...}` body) are unaffected, since their own `{` always arrives before any `;`. Bonus: this also surfaced and fixed a second instance of the same bug that the earlier corpus check missed -- `WWW_nameOfFile` in worldwideweb/HyperManager.m, another bodyless `extern` prototype that was being misattributed a body from a later unrelated brace. tree_sitter_accuracy_audit --all --ci now passes clean for all 31 languages (objective-c actually improved beyond its prior baseline: 2 pre-existing extra_functions -> 1). Golden masters re-blessed accordingly. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This was referenced Aug 14, 2026
Closed
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
func_starthas two alternatives: the-/+-prefixed method form (fixed for bodyless;termination in fix(objective-c): recover bodyless @interface method declarations #1332) and a plain C-style prototype form (extern void write_rtf_header(NXStream* rtfStream);). The C-style form was deliberately left brace-only in fix(objective-c): recover bodyless @interface method declarations #1332 since it had no exclusion shield and could already match a bare two-token call/return statement (return foo(x);) -- accepting;there too would have resurrected that false-positive class.{happened to appear later in the search window, and grabbed whatever unrelated{...}block was nearest as a bogus body (confirmed vialanguage-crucible/data/objective-c/worldwideweb/HyperText.h:write_rtf_headerwrongly spanned lines 19-30, stealing the@interfaceblock's own ivar-list braces several lines later).language_standards.py, mirrorsbranch's own control-flow keyword set:if|for|while|switch|return|else|case|default|do|break|continue|goto|sizeof|catch), closing off the bare-statement false-positive class at the syntactic level.detector.py, bodyless C-style prototypes are now explicitly excluded fromfunc_start's scope rather than recovered -- an earlier iteration of this PR tried accepting a bare;terminator the same way fix(objective-c): recover bodyless @interface method declarations #1332 did for the method alternative, buttree-sitter-accuracy-auditcorrectly flagged that as a regression: tree-sitter's own grammar parses a bodyless prototype as adeclarationnode, notfunction_definition, so the ground truth this repo measures against never counted prototypes as real functions in the first place (they have no executable logic to score). This matches the issue's own suggested alternative resolution. Real C-style function definitions (with an actual{...}body) are unaffected -- their own{always arrives before any;.Verification
write_rtf_headeris no longer matched at all (previously wrongly spanned lines 19-30 stealing an unrelated@interfaceblock's ivar-list braces).tests/tools/update_golden_master.py, both full-precision and zero-dependency modes): the fix also surfaced and corrected a second, previously-undetected instance of the same bug --WWW_nameOfFileinHyperManager.m, another bodylessexternprototype that was being misattributed a stolen body.python tests/tools/tree_sitter_accuracy_audit.py --all --cipasses clean for all 31 languages -- objective-c actually improved beyond its prior baseline (2 pre-existingextra_functions-> 1).python tests/tools/crucible_check.pypasses clean on both full-precision and zero-dependency venvs.python tests/tools/audit_check.py: all clear (regenerated the ruff baseline for pure line-shifts caused by the diff).tree-sitter-accuracy-auditandcrucible-audit(both modes).Test plan
pytest tests/extraction/languages/test_objectivec.py tests/extraction/languages/test_objectivec_strict.py tests/core_engine/test_detector.py-- 301 passed, including new regex-level valid/invalid cases and detector-level pipeline tests (test_objectivec_bodyless_c_style_prototype_excluded_not_misattributed,test_objectivec_c_style_real_definition_still_extracted,test_objectivec_c_style_bare_statement_not_misidentified_as_function)python tests/tools/tree_sitter_accuracy_audit.py --all --ci-- all 31 languages OKpython tests/tools/crucible_check.py-- full_precision + zero_dependency both PASSpython tests/tools/audit_check.py-- all clearCloses #1336
🤖 Generated with Claude Code