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

Isset check on array is loosing generic of the values #7511

Closed
VincentLanglet opened this issue Jun 22, 2022 · 5 comments
Closed

Isset check on array is loosing generic of the values #7511

VincentLanglet opened this issue Jun 22, 2022 · 5 comments
Labels
Milestone

Comments

@VincentLanglet
Copy link
Contributor

Bug report

Follow up of #7460
and #7500

It seems like when using array<T of Foo> and using isset() then accesing a value, the value is just considered as Foo.

Code snippet that reproduces the problem

Original issue:
https://phpstan.org/r/cfa53647-37aa-400e-8c4d-27ff902a807d

But this can be simplified to https://phpstan.org/r/0fc99af2-13fd-4c7f-bd43-06408b41e56f

@VincentLanglet
Copy link
Contributor Author

This works with

@phpstan-template T of PositionEntityInterface

but not

@phpstan-template T of PositionEntityInterface&TgEntityInterface

It might help to know what's the issue.
Where do you think I should look at to try to fix the bug @ondrejmirtes ?

@phpstan-bot
Copy link
Contributor

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

@@ @@
 24: Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
 30: Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), argument)
 33: Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), argument)
-34: Dumped type: PositionEntityInterface&TgEntityInterface
-36: Dumped type: PositionEntityInterface&TgEntityInterface
-42: Method HelloWorld::computeForFrontByPosition() should return array<T of PositionEntityInterface&TgEntityInterface> but returns array<PositionEntityInterface&TgEntityInterface>.
+34: Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
+36: Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
Full report
Line Error
24 Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
30 Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), argument)
33 Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), argument)
34 Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
36 Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)

@phpstan-bot
Copy link
Contributor

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

@@ @@
 24: Dumped type: array<T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)>
 29: Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
-31: Dumped type: PositionEntityInterface&TgEntityInterface
+31: Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
 34: Dumped type: array<T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)>
Full report
Line Error
24 Dumped type: array<T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)>
29 Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
31 Dumped type: T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)
34 Dumped type: array<T of PositionEntityInterface&TgEntityInterface (method HelloWorld::computeForFrontByPosition(), parameter)>

@VincentLanglet
Copy link
Contributor Author

Seems like you solved this issue @ondrejmirtes so I added a non-regression test phpstan/phpstan-src#1556

@github-actions
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 Aug 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants