Type the callable case of Option::ensure() - #86
Merged
Conversation
GrahamCampbell
force-pushed
the
polish-annotations
branch
from
August 24, 2026 00:41
92ffac8 to
f364632
Compare
GrahamCampbell
force-pushed
the
ensure-callable-type
branch
from
August 24, 2026 00:41
94e3238 to
b304325
Compare
GrahamCampbell
force-pushed
the
polish-annotations
branch
from
August 24, 2026 00:48
f364632 to
71cacc5
Compare
GrahamCampbell
force-pushed
the
ensure-callable-type
branch
from
August 24, 2026 00:49
b304325 to
6a6afea
Compare
GrahamCampbell
force-pushed
the
ensure-callable-type
branch
from
August 24, 2026 00:51
6a6afea to
eb9d458
Compare
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.
This stacks on #85 and types the callable case of
ensure(), which #84 left as a barecallablein 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 infersOption<string>instead of an option of the closure. Because the annotation now declarescallable():(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, becauseensure()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 mentioningensure()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.