Repository navigation
Conversation
With the default `$noneValue` (`null`), `Option\fromValue($nullableInt)` is now typed `Option<int>` instead of `Option<int|null>`. `null` is kept in the type when it can be a `Some` value: with a custom `$noneValue` or `$isSome`. The precise `$isSome` type lives in `@phpstan-param` (read by PHPStan and Mago) because Psalm drops the whole docblock when a `@param` type references `$value`. Custom none values (e.g. `false`) are not excluded: every formulation tried was either unsound in PHPStan or widened generic `fromValue($t)` to `Option<T|false>`. Closes texthtml#103 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #106 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 117 117
===========================================
Files 10 10
Lines 406 406
===========================================
Hits 406 406
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Closes #103
With the default
$noneValue(null),Option\fromValue()no longer keepsnullin the inner type:U|nullstripsnull;($value is null ? null : never)adds it back where it can be aSomevalue (custom$noneValue, or$isSome). SofromValue(?int, noneValue: 0)staysOption<int|null>, and the$isSomecallback is still typed as receivingnull(PHPStan & Mago rejectfn (int $i)for a?intvalue).$isSometype is in@phpstan-param(also read by Mago): Psalm silently drops the whole docblock when a@paramtype references$value. Psalm seescallable(mixed):bool, it was already blind to callback parameter types.fromValue($t)withT|nullisOption<T>. Known gap: in PHPStan, generic code with a custom$noneValue/$isSomenow getsOption<T|null>instead ofOption<T>.Not included
false, …):fromValue($line, noneValue: false)is stillOption<int|false>.$value is false-style conditionals make PHPStan widen genericfromValue($t)toOption<T|false>(regressing the default case), and$value is U|falseis always resolved as true by PHPStan, which is unsound (int|false|nullwithnoneValue: 0inferred asOption<int|null>).of()/tryOf()/ify()/tryIfy(): the equivalent needs conditionals on the callback return type ($callback is callable():null), which only PHPStan supports (Psalm: invalid docblock; Mago: not evaluated).Tests
New fixtures in
tests/type-hinting/option.php(nullable →Option<int>,falsekept, generic, custom$noneValuekeepsnull🎯,$isSomekeepsnull,$isSomecallback rejectingnull🎯 with a 🫥 psalm blind spot). PHPUnit, doctest, PHPStan, Psalm,mago analyze/lint/fmtpass.🤖 Generated with Claude Code