Skip to content

fix(extract): don't flag in-body function-like macro calls as parse gaps (#1071)#1135

Merged
DeusData merged 1 commit into
mainfrom
fix/1071-cpp-macro-type-arg
Jul 16, 2026
Merged

fix(extract): don't flag in-body function-like macro calls as parse gaps (#1071)#1135
DeusData merged 1 commit into
mainfrom
fix/1071-cpp-macro-type-arg

Conversation

@DeusData

Copy link
Copy Markdown
Owner

Problem (#1071)

A function-like macro invocation whose argument is a type token — e.g. SYNTH_ALLOC_ARRAY(char, n) — makes tree-sitter's C/C++ grammar emit an ERROR node (it parses char in expression position). cbm_collect_error_regions records that as a parse_partial coverage gap, even though the macro is #defined in the same file and nothing is actually missing from the graph. The reporter found this systematic across an allocation-macro-style corpus (built-in-type first arg: 43/45 invocations flagged; pointer-type: 17/17).

#define SYNTH_ALLOC_ARRAY(Type, Count) ((Type*)std::malloc(sizeof(Type) * (Count)))
Buffer make_buffer(std::size_t n) {
  Buffer b;
  b.data = SYNTH_ALLOC_ARRAY(char, n);   // <- flagged parse_partial before this fix
  ...
}

Fix

Subtract an error region only when it both:

  1. contains an invocation NAME( of a file-defined function-like macro (a Macro def that carries a parameter signature), and
  2. is fully enclosed by an extracted Function/Method body.

Condition (2) is the important guard. A top-level macro invocation is different — the macro may itself expand to a definition the original span doesn't contain (that's #949, extract_cpp_preproc_macro_generated_callable_skipped), which must stay flagged. Restricting suppression to in-body calls keeps #949 honest and fails safe: a benign top-level call stays flagged rather than a real gap being hidden.

Tests (reproduce-first, RED-verified)

  • extract_cpp_functionlike_macro_type_arg_no_false_parse_partial_issue1071 — RED-verified: with the suppression neutralized the file reports parse_incomplete=1, error_ranges=14-14; with the fix it's clean.
  • extract_cpp_real_in_body_error_still_flagged_issue1071 — a genuine in-body syntax error (int x = ;, no macro) still reports parse_incomplete — proves the suppression is tight.
  • Existing ...issue949 / ...issue946 parse-coverage tests preserved.

Full extraction (253) and pipeline (221) suites pass; lint-ci clean.

Closes #1071.

A function-like macro invocation whose argument is a type token — e.g.
ALLOC(int, n) — makes tree-sitter's C/C++ grammar emit an ERROR node (it parses
the type in expression position), which cbm_collect_error_regions recorded as a
parse_partial coverage gap. But the macro is #defined in the same file and the
call sits inside an already-extracted function body, so nothing is actually
missing from the graph — it's a benign call the grammar can't parse without the
preprocessor (#1071, systematic across allocation-macro-style codebases).

Subtract an error region only when it both (a) contains an invocation of a
file-defined function-like macro and (b) is fully enclosed by an extracted
Function/Method body. Condition (b) keeps a TOP-LEVEL macro invocation that
expands to a definition still flagged (#949: the generated def isn't in the
original span), and fails safe — a benign top-level call stays flagged rather
than a real gap being hidden.

Tests: a type-arg macro call inside a function no longer reports parse_partial;
a real in-body syntax error still does; #949/#946 preserved.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData enabled auto-merge July 16, 2026 16:20
@DeusData
DeusData merged commit 00719da into main Jul 16, 2026
21 checks passed
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.

Indexing gap: C++ function-like macro with type argument

1 participant