Skip to content
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

treatPhpDocTypesAsCertain: false leads to ERROR type #9307

Closed
schlndh opened this issue May 12, 2023 · 2 comments
Closed

treatPhpDocTypesAsCertain: false leads to ERROR type #9307

schlndh opened this issue May 12, 2023 · 2 comments
Labels
Milestone

Comments

@schlndh
Copy link

schlndh commented May 12, 2023

Bug report

I tried setting treatPhpDocTypesAsCertain: false and I got a bunch of weird issues reported. I eventually narrowed it down to this snippet: https://phpstan.org/r/31afc03c-8936-4cc4-b292-b48df3821292

IMO Dumped type: array<int|string, *ERROR*> is objectively wrong, since $items are certainly an array. (I'm not sure if *ERROR* makes sense here even if $items were non-iterable).

And then there's the second issue:

Parameter #1 $objects of method Aaa::acceptObjects() expects array<int, Item>, array<int|string, mixed> given.

I'm not sure if this is a consequence of the first issue, or if this is intended behavior. But in any case, it is not what I would expect based on the documentation of treatPhpDocTypesAsCertain. My understanding is that it should allow me to double-check if I'm getting the type specified in phpdoc or not, but it should otherwise assume that the phpdoc is correct.

Code snippet that reproduces the problem

https://phpstan.org/r/31afc03c-8936-4cc4-b292-b48df3821292 (same as above)

Expected output

It should behave the same as with treatPhpDocTypesAsCertain: true: Dumped type: array<int, Item>

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jun 30, 2023
@phpstan-bot
Copy link
Contributor

@schlndh After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-32: Dumped type: array<int|string, *ERROR*>
-34: Parameter #1 $objects of method Aaa::acceptObjects() expects array<int, Item>, array<int|string, mixed> given.
+32: Dumped type: array
Full report
Line Error
32 Dumped type: array

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants