Skip to content

fix: An empty argument slot with a name is not an ambiguous argument - #2850

Open
krlmlr wants to merge 1 commit into
mainfrom
claude/fix-named-empty-slot-8mj8p1
Open

fix: An empty argument slot with a name is not an ambiguous argument#2850
krlmlr wants to merge 1 commit into
mainfrom
claude/fix-named-empty-slot-8mj8p1

Conversation

@krlmlr

@krlmlr krlmlr commented Aug 16, 2026

Copy link
Copy Markdown
Contributor
as_adjacency_matrix(make_ring(4), a = )
  • CRAN 2.3.3: a 4×4 matrix
  • main: Error: Argument amatches multiple arguments ofas_adjacency_matrix().

#2812 taught the migration blocks to handle empty slots by asking base::missing() inside .old_signature() — which is right, and is what fixed the four #2646 revdeps. But two guards run before that closure is called, and both read argument names without ever looking at the values:

  • .arg_ambiguous, from names(substitute(...())), rejects an abbreviation that could mean two different arguments — 20+ functions.
  • .arg_forbidden, from names(sys.call()), rejects a tag that is a prefix of both a head formal and a recoverable one.

An empty slot supplies nothing, so it cannot be ambiguous between two arguments and cannot conflict with a formal. Under the old signature it matched by position and left the formal missing.

The change

Both guards drop empty slots before looking at names. The empty slot is the empty symbol — a symbol whose name is the empty string — and Filter() keeps the test to one expression, which matters because the block is # fmt: skip and every line of it is already long:

.arg_ambiguous <- base::intersect(base::names(base::Filter(function(.x) !(base::is.symbol(.x) && !base::nzchar(base::as.character(.x))), base::as.list(base::substitute(...())))), base::c("a", "at", "att"))

228 generated blocks, no line-count growth.

Verified against CRAN

2.3.3 main this branch
as_adjacency_matrix(make_ring(4), a = ) 4×4 error 4×4
as_adjacency_matrix(make_ring(4), sparse = ,) 4×4 4×4 4×4
as_adjacency_matrix(make_ring(4), ) 4×4 4×4 4×4
as_adjacency_matrix(make_ring(4), a = 1) error error error

The last row is the point: a value in the same slot is still rejected.

Tests

The empty-slot tests #2812 added only ever exercised migration_fixture, which carries neither guard — which is exactly why this survived. New tests cover both fixtures that do: migration_fixture_shadow for .arg_ambiguous, migration_fixture_prefix for .arg_forbidden, each with the empty slot accepted and a value rejected (snapshotted).

One more test pins #2646's two reproducers verbatim against real migrated functions rather than the fixture, plus the named-empty case on as_adjacency_matrix().

Full testthat::test_local() green apart from test-foreign.R:69, which downloads from github.com/igraph/graphsdb. Rscript tools/generate-migrations.R is idempotent on the committed tree, so the CI drift check passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01D1xpHRV7yVfgtJg4vp9P7z


Generated by Claude Code

```r
as_adjacency_matrix(make_ring(4), a = )
```

returns a 4x4 matrix on 2.3.3
and errors on the dev version with
"Argument `a` matches multiple arguments of `as_adjacency_matrix()`".

#2812 made the migration blocks handle empty slots
by asking `base::missing()` inside `.old_signature()`,
which is right and is what fixed the four #2646 revdeps.
But two guards run *before* that closure is called,
and both read argument names without looking at the values:

* `.arg_ambiguous`, from `names(substitute(...()))`,
  rejects an abbreviation that could mean two different arguments;
* `.arg_forbidden`, from `names(sys.call())`,
  rejects a tag that is a prefix of both a head formal
  and a recoverable one.

An empty slot supplies nothing,
so it cannot be ambiguous between two arguments
and cannot conflict with a formal --
the old signature would have matched it by position
and left the formal missing.

Both guards now drop empty slots first.
The empty slot is the empty symbol,
which is a symbol whose name is the empty string;
`Filter()` keeps the test to one expression,
which matters because the block is `# fmt: skip`
and every line of it is already long.

Tests cover the shape on both fixtures that carry a guard --
`migration_fixture_shadow` for `.arg_ambiguous`,
`migration_fixture_prefix` for `.arg_forbidden` --
which the empty-slot tests added by #2812 never touched,
and assert that a *value* in the same slot is still rejected.
One more test pins #2646's two reproducers verbatim
against real migrated functions rather than the fixture.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D1xpHRV7yVfgtJg4vp9P7z
@krlmlr krlmlr mentioned this pull request Aug 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 8c47c15 is merged into main:

  • ✔️as_adjacency_matrix: 735ms -> 737ms [-0.38%, +0.77%]
  • ✔️as_biadjacency_matrix: 741ms -> 740ms [-0.58%, +0.45%]
  • ✔️as_data_frame_both: 1.59ms -> 1.59ms [-1.12%, +1.57%]
  • ✔️as_long_data_frame: 4ms -> 4ms [-0.93%, +0.85%]
  • ✔️es_attr_filter: 2.68ms -> 2.68ms [-1.18%, +1.08%]
  • ✔️graph_from_adjacency_matrix: 115ms -> 115ms [-1.42%, +0.6%]
  • ✔️graph_from_data_frame: 3.68ms -> 3.69ms [-0.56%, +1.4%]
  • ✔️vs_attr_filter: 1.51ms -> 1.51ms [-1.76%, +1.29%]
  • ✔️vs_by_name: 971µs -> 965µs [-1.62%, +0.48%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

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.

2 participants