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

False positive when for in_array check with complex code path #6599

Closed
Seldaek opened this issue Feb 2, 2022 · 2 comments
Closed

False positive when for in_array check with complex code path #6599

Seldaek opened this issue Feb 2, 2022 · 2 comments
Labels
Milestone

Comments

@Seldaek
Copy link
Contributor

Seldaek commented Feb 2, 2022

See https://phpstan.org/r/c93e00ea-82a6-484a-b1e6-ac2a4f443693

The in_array() warning is wrong there at the end, as 10 may or may not be inside array{0: 10|20, 1?: 20} (which could be array{0: 20} for example.

In case it's more readable or to understand what the code does it comes from https://github.com/composer/composer/blob/6be6ce7d9f911c248139976703b73f4876c8a38f/src/Composer/Downloader/PathDownloader.php#L254-L279 originally.

@ondrejmirtes ondrejmirtes transferred this issue from phpstan/phpstan-strict-rules Feb 8, 2022
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Feb 8, 2022
@phpstan-bot
Copy link
Contributor

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

@@ @@
-17: Dumped type: array{0: 10|20, 1?: 20}
+17: Dumped type: array{0: 10, 1?: 20}|array{20}
 18: Dumped type: 10|20
-21: Dumped type: array{0: 10|20, 1?: 20}
-22: Dumped type: 10
-23: Call to function in_array() with arguments 20, array{0: 10|20, 1?: 20} and true will always evaluate to true.
+21: Dumped type: array{0: 10, 1?: 20}|array{20}
+22: Dumped type: 10
Full report
Line Error
17 `Dumped type: array{0: 10, 1?: 20}
18 `Dumped type: 10
21 `Dumped type: array{0: 10, 1?: 20}
22 Dumped type: 10

@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 Sep 29, 2022
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