Skip to content

fix(nargs): a Kotlin or C# primary constructor opens a function space - #1843

Merged
dekobon merged 3 commits into
mainfrom
fix/1828-nargs-primary-constructor
Nov 7, 2026
Merged

dekobon merged 3 commits into
mainfrom
fix/1828-nargs-primary-constructor

Conversation

@dekobon

@dekobon dekobon commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Fixes #1828.

What

A Kotlin primary constructor and a C# 12 primary constructor / positional record had their parameters counted nowhere: nargs read 0 on every space, so bca check --threshold nargs=5 passed a six-parameter constructor.

Each now opens a Function space named after its class, spanning the parameter list — Kotlin's primary_constructor node; C#'s parameter_list gated under a class, struct or record declaration (the one parent that is not a callable's parameters field). The gate, bca report, bca functions and the Python to_sarif binding all read Function rows, so the offender row is D::D: nargs = 6 in every front end with no scope change.

Three commits:

  1. fix(nargs): count a C# params array as one parameter — a pre-existing miscount found on the way: void F(params int[] xs) read 3 (4 with an attribute) because the grammar's hidden _parameter_array flattens its pieces into the list. The classic-vs-primary twin test cannot agree while that holds. Two corpus snapshots drop by two.
  2. fix(nargs): a Kotlin or C# primary constructor opens a function space — the fix. nom, wmc and npm count the constructor as one callable (Kotlin private/internal/protected constructor, sealed and enum classes non-public; C# always public per the spec). Kotlin val/var parameter properties stay the class's own npa (counted at the declaration visit). The superclass call : Base(x) stays the class's ABC branch (chore(csharp): reconcile is_call with abc.branches, and primary-constructor space attribution #1456 — it is the list's sibling). class G() is a declared zero-parameter constructor. C#'s byte-less is_func_space / get_space_kind are hand-written forwards (the under gate sets CHAIN_GATED), pinned as under-approximating and named in KNOWN_DISAGREEMENTS. One corpus snapshot gains a space (record Person).
  3. docs(lessons) — lesson 117 (a space's own value is everything the walk folds into it) plus one clause each into 63, 84, 89.

Decisions recorded

Verification

  • make pre-commit → BCA_GATE: pass on the final tree.
  • make bench-scaling: 119/119 probes in bound (one ancestors.parent per C# parameter_list).
  • Every new production arm perturbation-verified: removing it fails ≥1 new test and nothing else; dropping the npm row gate fails 12.
  • Review loop: simplify-rust, rust-optimize, audit-tests; then six parallel agents (review, code-review max, perf audit, under-reviewed consumers, astra-review, architecture audit) → 14 findings fixed, 3 declined with reasons; astra-review three passes on the remediation, the second of which caught my own invalid-Kotlin fixture (sealed … public constructor), fixed on the third.
  • Output submodule: dekobon/big-code-analysis-output main is at 5fbe03bf (two snapshot commits); gitlink and .role-coverage-observed.txt consistent per commit.

tree-sitter-c-sharp spells `params int[] xs` through the hidden
`_parameter_array` rule, whose pieces — the `params` token, the type,
the name and any attribute list — land directly in the `parameter_list`
where an ordinary parameter is one `parameter` node. The shared negative
filter counted every piece, so `void F(params int[] xs)` reported 3 and
`void F([A] params int[] xs)` 4.

C# now counts positively — one per `parameter`, one per `params` — for
every callable shape that can carry one: methods, constructors,
lambdas, anonymous methods and an indexer's bracketed list, each pinned
on its own space by `csharp_params_array_is_one_parameter`, which reads
3 / 4 against the shared filter. Two corpus snapshots drop by two.

Found while fixing #1828, whose classic-vs-primary constructor twin
cannot agree while `params` counts three.
A primary constructor's parameters counted nowhere: `NArgs::compute`
bills `is_func` and `is_closure` nodes, and neither Kotlin's
`primary_constructor` nor C#'s header `parameter_list` was either, so
`data class D(val a: Int, …, val f: Int)` and `class C(int a, …, int f)`
read `nargs` 0 on every space and `bca check --threshold nargs=5`
passed a six-parameter constructor.

Each now opens a `Function` space named after its class, spanning the
list, through the `FuncOpener` row — Kotlin's `PrimaryConstructor`;
C#'s `ParameterList` gated `under` a class, struct or record
declaration, the one parent that is not a callable's `parameters`
field — and the space owns the parameters. The gate, `bca report`,
`bca functions` and the Python `to_sarif` binding all read Function
rows, so none needs a scope change; the offender row is `D::D`.

The chain gate makes C#'s byte-less `is_func_space` / `get_space_kind`
hand-written forwards with a known-empty chain, as Ruby's are: they
keep the pre-#1828 answer for every parameter list, pinned by
`csharp_byte_less_spellings_omit_the_primary_constructor` and named in
`KNOWN_DISAGREEMENTS`. Both languages name the space from the parent
class in `get_func_space_name`, held to the climbing spelling by the
name-parity test; the default would read `<anonymous>`, which the gate
treats as a closure.

`nom`, `wmc` and `npm` each count the constructor as one callable:
`npm` reads it at the declaration, since neither body scan sees the
header, with a Kotlin `private` / `internal` / `protected constructor`,
a `sealed` class's and an `enum class`'s non-public and a C# primary
constructor public by the language. The superclass call stays the
class's ABC branch (#1456): it is the list's sibling. A Kotlin `val`
parameter property is visited inside the constructor space and reaches
the class's attribute sum through the roll-up. A written `class G()`
is a zero-parameter constructor; `class N` declares none. Java and
Groovy records without a compact constructor keep #1160's 0, now
named in the book's zero list.

One corpus snapshot gains a space (`record Person(string Name, int
Age)`); no Kotlin corpus file carries a primary constructor. The
promotion predicate is one `ancestors.parent` per C# parameter list;
`make bench-scaling` reports every probe within bound.

Fixes #1828
Lesson 117, from #1828: the first design billed a primary constructor's
parameters to the class and widened the `nargs` gate to containers, on
the premise that a container's own count could only be its
constructor's. Measured, a constructor-free Kotlin or Java class with
field lambdas already read `nargs.value 6`, because `own_args()` sums
the parameters of every spaceless lambda the walk folds into the
innermost space. The instruction: measure the admitted kind's own value
on inputs holding none of the construct before admitting it.

One clause each into the lessons whose mechanism the branch met again:
63 (opening a space re-parents what is counted inside it — the Kotlin
parameter properties), 84 (a review finding is prose — the `sealed …
public constructor` claim) and 89 (the open filter counting C#'s
flattened `params` pieces).
@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.40%. Comparing base (b85a3cb) to head (ac7cff4).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #1843    +/-   ##
========================================
  Coverage   98.39%   98.40%            
========================================
  Files         397      397            
  Lines      121287   121726   +439     
  Branches   120852   121291   +439     
========================================
+ Hits       119342   119781   +439     
  Misses       1223     1223            
  Partials      722      722            
Flag Coverage Δ
python 100.00% <ø> (ø)
rust 98.39% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
big-code-analysis-ast/src/checker.rs 96.79% <ø> (ø)
big-code-analysis-ast/src/checker/csharp.rs 100.00% <100.00%> (ø)
big-code-analysis-ast/src/getter.rs 95.71% <100.00%> (+0.05%) ⬆️
big-code-analysis-ast/src/getter/csharp.rs 100.00% <100.00%> (ø)
big-code-analysis-ast/src/getter/kotlin.rs 95.72% <100.00%> (+0.11%) ⬆️
big-code-analysis-ast/src/roles/csharp.rs 100.00% <ø> (ø)
big-code-analysis-ast/src/roles/kotlin.rs 100.00% <ø> (ø)
big-code-analysis-ast/src/roles/mod.rs 97.43% <ø> (ø)
src/metrics/abc.rs 99.73% <100.00%> (+<0.01%) ⬆️
src/metrics/abc/csharp.rs 94.71% <ø> (ø)
... and 8 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dekobon
dekobon merged commit ac7cff4 into main Nov 7, 2026
64 checks passed
@dekobon
dekobon deleted the fix/1828-nargs-primary-constructor branch November 7, 2026 23:33
dekobon added a commit that referenced this pull request Nov 9, 2026
PR #1843 (3e1c7e1, 6b15a74, ac7cff4) landed on main at 23:33 on
2026-11-07. PR #1844 (docs/agent-instructions) was cut from b85a3cb,
before #1843, never rebased, and squash-merged at 23:50 as ca56098.
A squash writes the PR's final tree over main as one commit, so
ca56098's diff against its own parent silently reverted every file
#1843 touched -- the role rows, checker, getter and metric changes,
their tests, the #1828 CHANGELOG and book entries, lesson 117, the
role baselines, and the big-code-analysis-output gitlink (5fbe03bf
back to d411e605) -- under a title that names only documentation.
On main at 784045c, `record R(int A, int B);` and
`data class D(val a: Int, ...)` again report nargs 0 with no function
space, the bug #1828 was closed for.

Re-apply `git diff b85a3cb ac7cff4` onto main. Every code, test
and snapshot hunk applied cleanly; CHANGELOG.md and
lessons_learned.md conflicted with the entries #1856 added since and
were resolved by keeping both (the #1828 lesson is 118, after
#1818's 117). The grammar-dispatch hunk is ported to its new home,
docs/development/grammar_dispatch.md section 7. .bca-baseline.toml
is regenerated with `make self-scan-write-baseline-headroom`; the
gitlink returns to 5fbe03bf, which is already on the submodule's
origin/main.

Verified: `bca check --threshold nargs=5` flags `D::D: nargs = 6`;
`Total(params int[] values)` reads 1; `make pre-commit` passes.

Fixes #1828
dekobon added a commit that referenced this pull request Nov 10, 2026
…ads its budget

Lessons 119 to 121, each drafted from PR #1862 and the incident
before it and checked against the code and the GitHub record:

- 119: a grammar whose `extras` holds a named non-comment node
  (tree-sitter-python's `line_continuation`) passes every
  `is_named() && kind != Comment` selector; five such sites, one
  predicate (#1830).
- 120: a role-row gate that reads bytes but is declared `gated_by`
  leaves `TEXT_GATED` false, so the byte-less forwards' compile-time
  asserts trust the declaration and hand it `&[]`; the chain axis has
  a behavioural backstop, the byte axis none (#1842, #1863).
- 121: a commit whose parent is the current tip can carry the old
  contents of files the tip changed as its own edit; ancestry says
  nothing, the PR's own diff does (PR #1844 over PR #1843, #1828).

`docs/development/testing.md` gains two subsections under "Fixture
shapes that cannot fail": a fixture that intercepts output prints it
when the test fails, and two correct outcomes separated by a clock are
one flake. The second describes the Claude hook's probe-budget test,
which this commit redesigns to match: the fixture's preload wraps
`setTimeout` and records the budget `run()` arms after each spawn, so
the test asserts a `--version` probe arms 3000 and the analyzer run
the override, instead of reading a reason string that a slow digest
start flips and a leaked override could hide behind. A leaked
override, a leaked override under a 1.2 s digest delay, and a check
that stops arming the override each fail it; it passes unmutated in
about 80 ms with no stalled probe.

Reviewed twice by astra-review; the first draft's claim that a squash
merge wrote a stale tree did not survive the record and is retracted
in the entry.
dekobon added a commit that referenced this pull request Nov 10, 2026
…ads its budget

Lessons 119 to 121, each drafted from PR #1862 and the incident
before it and checked against the code and the GitHub record:

- 119: a grammar whose `extras` holds a named non-comment node
  (tree-sitter-python's `line_continuation`) passes every
  `is_named() && kind != Comment` selector; five such sites, one
  predicate (#1830).
- 120: a role-row gate that reads bytes but is declared `gated_by`
  leaves `TEXT_GATED` false, so the byte-less forwards' compile-time
  asserts trust the declaration and hand it `&[]`; the chain axis has
  a behavioural backstop, the byte axis none (#1842, #1863).
- 121: a commit whose parent is the current tip can carry the old
  contents of files the tip changed as its own edit; ancestry says
  nothing, the PR's own diff does (PR #1844 over PR #1843, #1828).

`docs/development/testing.md` gains two subsections under "Fixture
shapes that cannot fail": a fixture that intercepts output prints it
when the test fails, and two correct outcomes separated by a clock are
one flake. The second describes the Claude hook's probe-budget test,
which this commit redesigns to match: the fixture's preload wraps
`setTimeout` and records the budget `run()` arms after each spawn, so
the test asserts a `--version` probe arms 3000 and the analyzer run
the override, instead of reading a reason string that a slow digest
start flips and a leaked override could hide behind. A leaked
override, a leaked override under a 1.2 s digest delay, and a check
that stops arming the override each fail it; it passes unmutated in
about 80 ms with no stalled probe.

Reviewed twice by astra-review; the first draft's claim that a squash
merge wrote a stale tree did not survive the record and is retracted
in the entry.

This branch was previously deployed

1 inactive deployment
github-pages — ac7cff45 Deployed Nov 7, 2026 by dekobon via deploy to GitHub Pages #1003
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.

fix(nargs): primary-constructor parameters count 0

1 participant