Skip to content

fix(objective-c): recover bodyless C-style prototypes in func_start - #1357

Merged
squid-protocol merged 2 commits into
mainfrom
fix/objc-c-style-prototype-bodyless-1336
Aug 12, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fix/objc-c-style-prototype-bodyless-1336

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Aug 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • objc's func_start has 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.
  • A real prototype was previously found only when a { happened to appear later in the search window, and grabbed whatever unrelated {...} block was nearest as a bogus body (confirmed via language-crucible/data/objective-c/worldwideweb/HyperText.h: write_rtf_header wrongly spanned lines 19-30, stealing the @interface block's own ivar-list braces several lines later).
  • Fix, in two parts:
    1. A "not a function" keyword shield in the regex itself (language_standards.py, mirrors branch'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.
    2. In detector.py, bodyless C-style prototypes are now explicitly excluded from func_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, but tree-sitter-accuracy-audit correctly flagged that as a regression: tree-sitter's own grammar parses a bodyless prototype as a declaration node, not function_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_header is no longer matched at all (previously wrongly spanned lines 19-30 stealing an unrelated @interface block's ivar-list braces).
  • Golden masters re-blessed (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_nameOfFile in HyperManager.m, another bodyless extern prototype that was being misattributed a stolen body.
  • python tests/tools/tree_sitter_accuracy_audit.py --all --ci passes clean for all 31 languages -- objective-c actually improved beyond its prior baseline (2 pre-existing extra_functions -> 1).
  • python tests/tools/crucible_check.py passes clean on both full-precision and zero-dependency venvs.
  • Full local test suite: 6843 passed.
  • python tests/tools/audit_check.py: all clear (regenerated the ruff baseline for pure line-shifts caused by the diff).
  • All CI checks green, including tree-sitter-accuracy-audit and crucible-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 OK
  • python tests/tools/crucible_check.py -- full_precision + zero_dependency both PASS
  • python tests/tools/audit_check.py -- all clear

Closes #1336

🤖 Generated with Claude Code

…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]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…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]>
@squid-protocol
squid-protocol merged commit 069d5b5 into main Aug 12, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/objc-c-style-prototype-bodyless-1336 branch August 12, 2026 16:44
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.

objective-c: bodyless C-style prototypes are only found by accident, with a wrong body span

1 participant