-
Notifications
You must be signed in to change notification settings - Fork 548
More precise return type for gatherAssertTypes #4614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| if ($args[0] === 'type') { | ||
| $file = $args[1]; | ||
|
|
||
| if ($assertType === 'type') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not really a solution I was looking for 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to fix this, we need to resolve: https://phpstan.org/r/14f80375-8f26-4720-a551-5db44aaca71c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed the wrong return-type
|
Awesome, thank you! |
No description provided.