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 in composer #9985

Closed
greew opened this issue Oct 6, 2023 · 5 comments
Closed

False positive in composer #9985

greew opened this issue Oct 6, 2023 · 5 comments

Comments

@greew
Copy link

greew commented Oct 6, 2023

Bug report

After upgrading to 1.10.37, a new false positive has surfaced in https://github.com/composer/composer/blob/main/src/Composer/Command/DiagnoseCommand.php#L702

I have reproduced the bug in the playground.

If I

  • remove line 5-7
  • change line 11 to a simple else
  • remove the the empty check (line 15)
    the error doesn't appear. It takes this specific setup to make it appear.

Code snippet that reproduces the problem

https://phpstan.org/r/5eb1279c-18a6-4243-ad3c-7d223a68f8c4

Expected output

I expected

 ------ -----------------------------------------------------------------------------
  Line   test.php
 ------ -----------------------------------------------------------------------------
  15     Construct empty() is not allowed. Use more strict comparison.
 ------ -----------------------------------------------------------------------------

but got

 ------ -----------------------------------------------------------------------------
  Line   test.php
 ------ -----------------------------------------------------------------------------
  15     Construct empty() is not allowed. Use more strict comparison.
  19     Switch condition type ('a'|'c') does not match case condition 'b' (string).
 ------ -----------------------------------------------------------------------------

Did PHPStan help you today? Did it make you happy in any way?

Thank you for a great product!

@Seldaek
Copy link
Contributor

Seldaek commented Oct 6, 2023

It seems to me the problem is in the handling of empty(), this with debug output highlights well how after empty it has merged the 3 states (empty array, array with a+b or array with a+c) into one non empty array with a+c but b is gone.

https://phpstan.org/r/3974e839-40bf-4176-b035-2acea52390c3

@greew
Copy link
Author

greew commented Oct 6, 2023

Great! Thank you for helping with how the debug works. I haven't tried it before! :)

@ondrejmirtes
Copy link
Member

Fixed, gonna release PHPStan 1.10.38 with this fix soon: phpstan/phpstan-src@746de74

@Seldaek
Copy link
Contributor

Seldaek commented Oct 6, 2023

No rush for me :) But thanks!

Copy link

github-actions bot commented Nov 7, 2023

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 Nov 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants