Skip to content

fix(core): args regex capture group missing in 25 languages (regression from #1199 Python fix) #1209

Closed

Description

@squid-protocol

What

PR #1207 (merged 2026-08-10) fixed a regression in function parameter-counting (function_data.args) for Python by adding a capture group to its args regex in gitgalaxy/standards/language_standards.py. That fix applied only to Python (python/embedded_python); the underlying bug mechanism affects a further set of languages with the same structural precondition: a zero-capture-group args regex pattern that also genuinely represents a comma/space-separated parameter list.

EDIT (post-filing correction): the original version of this issue listed 34 languages, based purely on args_pattern.groups == 0. Re-reading each of those 34 regexes individually found that 9 are false positives — their args rule doesn't represent a function parameter list at all, so this bug doesn't apply to them (see "Not affected" below). The real, corrected scope is 25 languages, split into two tiers by how directly Python's fix pattern transfers.

Root cause

Each language's args regex is consumed by gitgalaxy/core/detector.py's _calculate_block_metrics function:

arg_match = args_pattern.search(block)
args_str = arg_match.group(arg_match.lastindex) if arg_match.lastindex else arg_match.group(0)

When args_pattern.groups == 0 (no capture group defined), arg_match.lastindex is None, so the code falls back to the WHOLE match text — e.g., "func main()" including the keyword and function name, not just the parameter list "()". This whole-text capture then gets split on whitespace and counted as tokens, hitting a zero/one-arg signature with no comma against a fallback meant for space-separated languages (Lisp/Scheme), and miscounting "func main()".split() as ["func", "main()"] → 2 args for a function that actually takes 0.

Verified as real in Go, Rust, Java (confirmed via actual detector pipeline against zero-arg and multi-arg samples). Inferred for the remaining languages in Tier 1 based on the same structural precondition and regex shape, not yet independently verified in each language.

Tier 1 — mechanical fix (20 languages)

Same keyword name(...) shape as Python/Go/Rust/Java (a single parenthesized, comma-separated parameter list). Python's exact fix pattern should transfer directly:

c, cpp, csharp, java, javascript, typescript, kotlin, swift, dart, scala, groovy, go, rust, php, ruby, perl, lua, solidity, apex, powershell

Tier 2 — needs individual judgment (5 languages)

Real bug (the same whole-match fallback mechanism applies), but the signature shape doesn't match Python's single-paren-comma-list model, so the fix needs per-language thought rather than a blind port:

  • objective-c — colon-selector method syntax (doThing:(int)x withOther:(int)y); parameters aren't inside one comma-separated (...) block.
  • scheme — genuinely space-separated inside (define (name a b) ...), not comma-separated; the existing whitespace-split fallback is closer to correct in intent but still picks up the (define/name tokens as spurious args.
  • matlab — function [outputs] = name(inputs); there's an output list before the = in addition to the real input-parameter parens, needs care to only count the input side.
  • haskell — matches type signatures (::) and lambdas; idiomatic Haskell functions are often curried with no parens at all (add x y = x + y), so "args count" doesn't map onto this regex the same way.
  • fortran — parens are optional in the pattern ((?:\s*\([^)]*\))?) and the alternation also matches unrelated INTENT/VALUE/OPTIONAL keyword usage, not just declarations.

Not affected — false positives, removed from scope (9 languages)

These were in the original 34-language list purely because groups == 0, but their args rule measures something other than a function's parameter list, so this bug doesn't apply:

Language What args actually matches Why it's a different thing
dockerfile ARG instruction lines Dockerfiles have no functions
makefile $(1), $(call ...) Make variable references, not a param list
yacc $1, $<type>1 Bison semantic-value references
m4 $1, $@ Macro-argument references
shell $1, $@ usage inside a function body Same shape as makefile/yacc — not a signature
agc_assembly Opcode/operand mnemonics Not a signature at all
sqlite ?1, :name, VALUES(...), WITH...AS SQL placeholders/CTEs, not function params
css calc(...), var(...), etc. Built-in value-function call sites, not user function declarations
yaml GitHub Actions with: block Workflow step inputs, unrelated concept

If these are worth revisiting at all, it would be as a separate, differently-scoped issue about whether args is even the right rule name/purpose for them — not this bug.

The fix pattern (Tier 1)

For each Tier 1 language, add a capture group around just the parameter-list span in that language's args regex, positioned so re.Match.lastindex resolves to it (i.e., make it the LAST/highest-numbered participating capture group in whichever alternation branch matches).

Reference: Python's fixed args rule (search language_standards.py for the python language block) — it wraps the parameter list in (\(...\)) so args_str becomes exactly "(...)" with no keyword prefix. The existing _calculate_block_metrics and _count_top_level_args logic already correctly handles this clean capture for Python; no changes to detector.py are needed for Tier 1.

What does NOT need fixing

References

Completion checklist

Tier 1 (mechanical)

  • c
  • cpp
  • csharp
  • java
  • javascript
  • typescript
  • kotlin
  • swift
  • dart
  • scala
  • groovy
  • go
  • rust
  • php
  • ruby
  • perl
  • lua
  • solidity
  • apex
  • powershell

Tier 1 is now fully complete (PR #1212: c/cpp/go/kotlin/swift/php/perl/lua/apex/rust/solidity/scala/dart. PR #1216: csharp/java/javascript/typescript/groovy/ruby/powershell).

Tier 2 is now also fully complete (PR #1218: objective-c/scheme/matlab/haskell/fortran — each needed a bespoke counting strategy, not a mechanical port; see the PR for the per-language design). All 25 languages in scope are fixed. Closing.

Tier 2 (needs individual judgment — separate follow-up pass)

  • objective-c
  • scheme
  • matlab
  • haskell
  • fortran

Activity

  1. added
    bug
    core-engine
    on Aug 10, 2026
  2. changed the title [-]fix(core): add args regex capture group for 34 languages (regression from #1199 Python fix)[/-] [+]fix(core): args regex capture group missing in 25 languages (regression from #1199 Python fix)[/+] on Aug 10, 2026
  3. squid-protocol commented on Aug 10, 2026

    @squid-protocol
    OwnerAuthor

    Re-triaged the original 34-language list before starting implementation: 9 of them (dockerfile, makefile, yacc, m4, shell, agc_assembly, sqlite, css, yaml) turned out to be false positives — their args rule matches something other than a function parameter list entirely (Dockerfile ARG lines, Make/Bison/m4 variable references, SQL placeholders, CSS built-in value functions, GitHub Actions workflow inputs), so this bug doesn't apply to them. Corrected scope is 25 languages, split into a 20-language mechanical tier and a 5-language tier needing individual judgment (objective-c, scheme, matlab, haskell, fortran — real bug, but the signature shape doesn't match Python's single-paren-comma-list model). Issue body and checklist updated accordingly. Starting on the Tier 1 mechanical batch now.

  4. squid-protocol commented on Aug 10, 2026

    @squid-protocol
    OwnerAuthor

    PR #1212 fixes the first 13 of Tier 1's 20 languages: c, cpp, go, kotlin, swift, php, perl, lua, apex, rust, solidity, scala, dart. Checklist updated. Also added persisted regression coverage that neither this issue nor #1199 had before (a shared-helper unit test plus a per-language real-pipeline parametrized test in tests/core_engine/test_detector.py) -- extending that same fixture dict is the expected pattern for the remaining languages.

    Remaining in Tier 1: csharp, java, javascript, typescript, groovy, ruby, powershell -- these have multi-branch args regexes (separate alternatives for functions/arrow-functions/methods/getters-setters/decorators) needing the same per-branch capture-group treatment cpp/kotlin/swift/rust/scala did here, so they're a distinct, more expensive follow-up pass rather than a continuation of this same PR.

  5. squid-protocol commented on Aug 10, 2026

    @squid-protocol
    OwnerAuthor

    PR #1216 fixes the remaining 7 Tier 1 languages: csharp, java, javascript, typescript, groovy, ruby, powershell. Tier 1 (20/20) is now complete.

    Notable findings from this batch:

    The ARGS_COUNT_FIXTURES regression suite (added in PR #1212) now covers 20/20 Tier 1 languages, 21 parametrized cases total.

    Remaining: the 5-language Tier 2 (objective-c, scheme, matlab, haskell, fortran) -- structurally unlike Python's model, each needs individual design thought rather than the mechanical capture-group port used here.

  6. squid-protocol commented on Aug 10, 2026

    @squid-protocol
    OwnerAuthor

    PR #1218 fixes the remaining 5 Tier 2 languages: objective-c, scheme, matlab, haskell, fortran. All 25 languages are now fixed — closing this issue.

    Each Tier 2 language needed a genuinely bespoke counting strategy rather than the mechanical capture-group port used for Tier 1:

    • objective-c: keyword-message selectors don't have a comma-separated list at all -- new _count_colon_selector_segments counts repeated label:(Type)name segments instead.
    • scheme: args are space-separated inside the SAME parens as the name -- split into separate capture groups so the existing whitespace-split fallback works correctly.
    • matlab: function [out1, out2] = name(in1, in2) -- the fix specifically targets only the trailing INPUT parens, never miscounting the output-variable list as if it were part of the signature.
    • haskell: name :: Int -> Int -> Int has no parens/commas at all -- new _count_haskell_type_arrows counts curried arity from top-level arrow count, gated on a new per-group opt-in flag (_args_arrow_count_groups) since a real signature can have zero arrows and still need a correct zero count.
    • fortran: SUBROUTINE Foo (no parens) is valid zero-arg syntax -- the args group now has an empty-string alternative so it still participates and correctly counts zero.

    Two additional, unplanned findings surfaced while verifying these against ReDoS scaling sweeps (now part of standard practice for any args-regex edit per this repo's own protocol):

    • A new ReDoS in objective-c's fix itself (an added optional-label group introduced unbounded backtracking) -- caught and fixed before merge.
    • A genuine pre-existing ReDoS in scheme's args regex, unrelated to fix(core): args regex capture group missing in 25 languages (regression from #1199 Python fix) #1209 and confirmed present in the regex before any of this issue's changes (two adjacent unbounded quantifiers, O(n²) confirmed via scaling sweep) -- fixed as a drive-by since I was already touching that exact line.

    Also documented (not fixed, out of scope): scheme/matlab and some haskell/fortran signature shapes aren't actually extracted by the real detector pipeline at all -- a separate, pre-existing recall gap (paren-/keyword-delimited languages don't fit the generic Mode B brace-slicer). New regression tests for these call _calculate_block_metrics directly to isolate and pin the counting fix independent of that gap.

    Full summary across all four PRs: #1207 (Python, originating fix) → #1212 (13 languages) → #1216 (7 languages) → #1218 (5 languages) = 25 languages total, all verified individually against real signatures, existing extraction test suites, and (for the languages that reach it) the real pipeline.

  7. added 3 commits that reference this issue on Aug 10, 2026
    d111d20
    1860ee7
    e6a70aa
  8. added this to the v2.4.8 milestone on Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions