Skip to content

Type the callable case of Option::ensure() - #86

Merged
GrahamCampbell merged 1 commit into
masterfrom
ensure-callable-type
Aug 24, 2026
Merged

Type the callable case of Option::ensure()#86
GrahamCampbell merged 1 commit into
masterfrom
ensure-callable-type

Conversation

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

This stacks on #85 and types the callable case of ensure(), which #84 left as a bare callable in the union, so a closure argument bound the template to the closure type itself rather than to what it returns; ensure(fn (): string => 'x') now infers Option<string> instead of an option of the closure. Because the annotation now declares callable():(S|Option<S>), static analysers will begin flagging two patterns that were previously accepted: callables that require arguments, and literal function-name strings passed as the value. Both of these already fail at runtime, because ensure() invokes callables with zero arguments and treats a string as a plain value only if it is not callable, so the new errors point at pre-existing latent bugs rather than breaking valid code, though consumer baselines with entries mentioning ensure() may need regenerating, and the release notes should mention the change. Callables whose arguments are all optional remain accepted. This is an annotation-only change with no runtime impact, so no tests are added, and the library's own PHPStan baseline is untouched.

Base automatically changed from polish-annotations to master August 24, 2026 00:49
@GrahamCampbell
GrahamCampbell merged commit 67b192b into master Aug 24, 2026
22 of 23 checks passed
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