Skip to content

fix(erlang): don't count comments as arguments when computing arity - #1619

Open
Dshuishui wants to merge 1 commit into
colbymchenry:mainfrom
Dshuishui:fix/erlang-arity-comments
Open

fix(erlang): don't count comments as arguments when computing arity#1619
Dshuishui wants to merge 1 commit into
colbymchenry:mainfrom
Dshuishui:fix/erlang-arity-comments

Conversation

@Dshuishui

@Dshuishui Dshuishui commented Aug 26, 2026

Copy link
Copy Markdown

Follow-up to #1615, rebased onto main now that it has landed.

Arity is computed with namedChildCount, but tree-sitter reports comment as a named child, so a comment at the top level of a parameter or argument list inflates it:

plain( % a comment
    1, 2)          % counted as plain/3 — the edge is dropped

withdef(X, % a comment
        Y) -> ...  % indexed as withdef/3

Same for the MFA list in spawn(?MODULE, f, [A, % note\n B]). A comment nested one level deeper (inside #state{...}, a tuple, a list) is unaffected — only the top level of the list counts.

This surfaced with #1615: before it, arity took no part in resolution, so the miscount was harmless. Now arity is identity, so one extra unit silently drops the edge.

Small blast radius. Across cowboy, ranch, jsx, rebar3 and fast_xml only rebar3 is affected, losing two real edges (rebar_compiler.erl:403, rebar_release_SUITE.erl:247); re-indexing those five with this patch changes nothing else — no nodes added or removed, no edges removed, exactly those two edges restored.

The three counts now go through one namedArgCount helper so the invariant is stated once.

The new test in erlang-arity-resolution.test.ts covers the four shapes above. I checked it is not vacuous: on main without this patch it fails, and it passes with it. The full suite passes (3,053).

No CHANGELOG entry — #1615's entry already describes the user-visible behaviour, and the trigger here is rare; this just keeps that rare case from silently dropping edges.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

tree-sitter reports `comment` as a named child, so a comment written at
the top level of a parameter or argument list inflated the arity taken
from `namedChildCount`: `plain( % note\n 1, 2)` read as plain/3 and the
edge was dropped, and `f(X, % note\n Y) ->` was indexed as f/3. The MFA
list in `spawn(?MODULE, f, [A, % note\n B])` had the same problem.

Arity only became part of a function's identity in colbymchenry#1610, so the
miscount was harmless before that. The three counts now share one
`namedArgCount` helper so the invariant is stated once.
@Dshuishui
Dshuishui force-pushed the fix/erlang-arity-comments branch from d54be5c to 9bf68eb Compare August 26, 2026 15:48
@Dshuishui
Dshuishui changed the base branch from fix/1610-erlang-arity-nodes to main August 26, 2026 15:48
@Dshuishui

Copy link
Copy Markdown
Author

Rebased onto main now that #1615 has merged, and retargeted this PR from the (now-merged) topic branch to main. Same single commit, unchanged.

Re-verified on current main: the miscount is still there (all three namedChildCount sites), the new test fails without this patch and passes with it, and the full suite is green.

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.

1 participant