Repository navigation
fix(nargs): a Kotlin or C# primary constructor opens a function space - #1843
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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
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.
Fixes #1828.
What
A Kotlin primary constructor and a C# 12 primary constructor / positional record had their parameters counted nowhere:
nargsread 0 on every space, sobca check --threshold nargs=5passed a six-parameter constructor.Each now opens a
Functionspace named after its class, spanning the parameter list — Kotlin'sprimary_constructornode; C#'sparameter_listgatedundera class, struct or record declaration (the one parent that is not a callable'sparametersfield). The gate,bca report,bca functionsand the Pythonto_sarifbinding all read Function rows, so the offender row isD::D: nargs = 6in every front end with no scope change.Three commits:
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_arrayflattens its pieces into the list. The classic-vs-primary twin test cannot agree while that holds. Two corpus snapshots drop by two.fix(nargs): a Kotlin or C# primary constructor opens a function space— the fix.nom,wmcandnpmcount the constructor as one callable (Kotlinprivate/internal/protected constructor,sealedandenumclasses non-public; C# always public per the spec). Kotlinval/varparameter properties stay the class's ownnpa(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-lessis_func_space/get_space_kindare hand-written forwards (theundergate setsCHAIN_GATED), pinned as under-approximating and named inKNOWN_DISAGREEMENTS. One corpus snapshot gains a space (record Person).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
own_args()already carries folded field-lambda parameters — a constructor-free Kotlin/Java class with comparator fields measuresnargs.value 6onmain— so widening the gate to containers would have flagged those; and nothing counted the constructor in the average's divisor.<anonymous>(pre-existing;secondary_constructorhas nonamefield). Noted in the book.Verification
make pre-commit→BCA_GATE: passon the final tree.make bench-scaling: 119/119 probes in bound (oneancestors.parentper C#parameter_list).npmrow gate fails 12.simplify-rust,rust-optimize,audit-tests; then six parallel agents (review,code-reviewmax, perf audit, under-reviewed consumers,astra-review, architecture audit) → 14 findings fixed, 3 declined with reasons;astra-reviewthree passes on the remediation, the second of which caught my own invalid-Kotlin fixture (sealed … public constructor), fixed on the third.dekobon/big-code-analysis-outputmainis at5fbe03bf(two snapshot commits); gitlink and.role-coverage-observed.txtconsistent per commit.