Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Dec 4, 2025

No description provided.

if ($args[0] === 'type') {
$file = $args[1];

if ($assertType === 'type') {
Copy link
Contributor Author

@staabm staabm Dec 4, 2025

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, (
Copy link
Contributor Author

@staabm staabm Dec 4, 2025

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

@staabm
Copy link
Contributor Author

staabm commented Dec 4, 2025

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

Copy link
Member

@ondrejmirtes ondrejmirtes left a 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
Copy link
Member

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 😊

Copy link
Contributor Author

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 ;)

Copy link
Contributor Author

@staabm staabm Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

@ondrejmirtes ondrejmirtes merged commit 1d86de8 into phpstan:2.1.x Dec 4, 2025
619 of 637 checks passed
@ondrejmirtes
Copy link
Member

Awesome, thank you!

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.

2 participants