Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Dec 12, 2022

closes phpstan/phpstan#8485

for comparison see the handling of regular constants/class-constants: https://phpstan.org/r/a6a9d005-a9d5-4f7d-86ad-00a3a3422cec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new error is a bit misleading. not sure we want to keep it like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in contrast, I like this error way more then the one we had before this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use EnumCaseObjectType::equals() instead.

Copy link
Contributor Author

@staabm staabm Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch - fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@staabm staabm marked this pull request as ready for review December 13, 2022 08:18
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 5fc2bfd into phpstan:1.9.x Dec 13, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the identical-enum branch December 13, 2022 08:35
@ondrejmirtes
Copy link
Member

Sorry, I had to revert this, it's pretty annoying in practice. We first need to do a different feature in order for this one to be less annoying.

@staabm
Copy link
Contributor Author

staabm commented Dec 13, 2022

no problem. in case there is something I can do, please open a issue about the thing we need, so I can investigate.

@ondrejmirtes
Copy link
Member

The problem is that this now reports "always true" for the last elseif in an if-elseif-else blocks. In real-world projects this now reports dozens of new errors.

Also arguably last match arm shouldn't report this. Because people might prefer to write Foo::Bar => doFoo() instead of default => doFoo() to be notified when there's a new enum case to handle.

So, I have an idea: We need a new custom node visitor to mark the condition expression in last match arm and last elseif with an attribute. And ConstantConditionRuleHelper can use this node attribute to decide that "always true" shouldn't be reported there.

There's already an issue for this: phpstan/phpstan#8042

And after this is implemented, we can afford to report all "always true" conditions for everyone in bleedingEdge/2.0, not just phpstan-strict-rules users. Because the most annoying ones will not be reported anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Same enums comparison is not reported

3 participants