More precise return type for gatherAssertTypes#4614
More precise return type for gatherAssertTypes#4614ondrejmirtes merged 8 commits intophpstan:2.1.xfrom
Conversation
| if ($args[0] === 'type') { | ||
| $file = $args[1]; | ||
|
|
||
| if ($assertType === 'type') { |
There was a problem hiding this comment.
phpstan is not able to narrow the array-shape of the tagged union of $args based on array_shift() (which is equivalent to $args[0]).
rewrote the logic so PHPStan is able to narrow the tagged union
| } | ||
|
|
||
| /** | ||
| * @return array<string, ( |
There was a problem hiding this comment.
goal of this PR is, to have a more precise return type here, so downstream projects which use TypeInferenceTestCase can properly utilize the PHPUnit Data-Provider validation capabilities on level 8
see e.g. phpstan/phpstan-webmozart-assert#193
|
I think with this change, we can now put level 9 back onto phpstan/webmozarts-assert without errors. it was a chicken egg problem, which needs adjustments in in both repos, to get finally green again |
ondrejmirtes
left a comment
There was a problem hiding this comment.
I copied the PHAR from here and it makes phpstan-webmozart-assert green on L9 even without removing the PHPDocs there. That's good. But PHPStan shouldn't throw any errors here. We should know when the method returns something bad so ignoring isn't an option.
|
|
||
| if (count($delayedErrors) === 0) { | ||
| return $asserts; | ||
| return $asserts; // @phpstan-ignore return.type |
There was a problem hiding this comment.
That's not really a solution I was looking for 😊
There was a problem hiding this comment.
of course not. but that needs fixing a bug unrelated to the change/goal of this PR here ;)
There was a problem hiding this comment.
to fix this, we need to resolve: https://phpstan.org/r/14f80375-8f26-4720-a551-5db44aaca71c
There was a problem hiding this comment.
fixed the wrong return-type
|
Awesome, thank you! |
No description provided.