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

Wrong understanding of array content in ternary operator #7686

Closed
zeleznypa opened this issue Jul 25, 2022 · 2 comments · Fixed by phpstan/phpstan-src#2230
Closed

Wrong understanding of array content in ternary operator #7686

zeleznypa opened this issue Jul 25, 2022 · 2 comments · Fixed by phpstan/phpstan-src#2230
Labels
Milestone

Comments

@zeleznypa
Copy link

Bug report

PHPStan shows the error, that „Else branch“ is unreachable in ternary operator, but it is not true.

Code snippet that reproduces the problem

https://phpstan.org/r/5004a3b9-ccaa-4a72-8d05-32263f9bc57f

Expected output

Expected output is correct state:

https://3v4l.org/4PNGk

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

Sometimes PHPStan find for me a very ugly bug like wrong position of closing brackets.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 25, 2022
@phpstan-bot
Copy link
Contributor

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

@@ @@
 19: Else branch is unreachable because ternary operator condition is always true.
-21: Method Foo::test() should return array<'return'|int, string> but returns array<string, ''>.
+21: Method Foo::test() should return array<'return'|int, string> but returns array<int|string, ''>.
Full report
Line Error
19 Else branch is unreachable because ternary operator condition is always true.
21 `Method Foo::test() should return array<'return'

@github-actions
Copy link

github-actions bot commented May 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 May 7, 2023
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