close
Skip to content

Add @only-named-arguments annotation#11791

Open
GromNaN wants to merge 1 commit intovimeo:6.xfrom
GromNaN:feature/only-named-arguments
Open

Add @only-named-arguments annotation#11791
GromNaN wants to merge 1 commit intovimeo:6.xfrom
GromNaN:feature/only-named-arguments

Conversation

@GromNaN
Copy link
Copy Markdown
Contributor

@GromNaN GromNaN commented Apr 10, 2026

Fixes #11763

Adds a @only-named-arguments docblock annotation that requires callers to use named arguments. This is useful for libraries that want to enforce named-argument call sites as part of their BC policy — allowing parameter reordering or removal without breaking positional callers.

When a positional argument is passed to a function or method annotated with @only-named-arguments, Psalm emits the new PositionalArgumentNotAllowed issue. Spread/unpack calls are also covered: foo(...[0, 1]) triggers the issue while foo(...['a' => 0, 'b' => 1]) is allowed.

Using both @only-named-arguments and @no-named-arguments on the same declaration is flagged as InvalidDocblock.

For variadic parameters, the inferred type of ...$args becomes array<string, T> (instead of list<T> with @no-named-arguments or array<array-key, T> without annotation).

@only-named-arguments takes priority over the global allowInternalNamedArgumentCalls="false" and allowNamedArgumentCalls="false" config options, allowing library authors to selectively enforce named arguments on specific APIs even in codebases that otherwise disable named argument calls.

@GromNaN GromNaN force-pushed the feature/only-named-arguments branch 4 times, most recently from 8684563 to 895c4b3 Compare April 10, 2026 20:28
@GromNaN GromNaN force-pushed the feature/only-named-arguments branch from 895c4b3 to b070c35 Compare April 11, 2026 19:55
Comment thread config.xsd Outdated
@GromNaN GromNaN force-pushed the feature/only-named-arguments branch from b070c35 to ddbbc93 Compare April 12, 2026 08:32
@GromNaN GromNaN force-pushed the feature/only-named-arguments branch from ddbbc93 to 038317b Compare April 12, 2026 11:19
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 038317b. Configure here.

@GromNaN GromNaN force-pushed the feature/only-named-arguments branch from 038317b to 3ebb823 Compare April 13, 2026 10:10
@GromNaN GromNaN force-pushed the feature/only-named-arguments branch from 3ebb823 to 9fed2de Compare April 13, 2026 10:20
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.

Add support for requiring the usage of named arguments

1 participant