-
Notifications
You must be signed in to change notification settings - Fork 507
Implement identical/equal comparisons on EnumCaseObjectType #2105
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
Conversation
I decided against implementing the check in |
Sure, these rules needed update too, but I really need this in the helper. The idea is to stop reporting each "always true" in the last elseif and last match arm :) Also make sure to test that these "always true" are still being reported when in not-last elseif and match arm etc. :) Thank you. |
what about phpstan-src/tests/PHPStan/Rules/Comparison/data/strict-comparison.php Lines 647 to 660 in 926ec9d
do we expect a error on line 654, or should this also be prevented? before this PR we get an error there. |
ok reading this again, I think it should not be reported. we want to stop reporting of each "always true" |
echo 'nope'; | ||
} elseif ('foofoofoofoofoofoofob' === $value) { | ||
echo 'nop nope'; | ||
} elseif (rand(0, 1) === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a new variant of the existing test in the same file on line 654, with a additional else-if so we can see the error are reported when its not the last else-if
9930911
to
98c0b3d
Compare
since this PR already fixes 4 open issues and AFAIK will fix the anoying errors the 1st implementation had I think we should consider merging it. Taking the new visitor into account in ConstantConditionRuleHelper and all related rules can be done in a separate PR.. wdyt? |
This pull request has been marked as ready for review. |
Something is broken here, the pipeline didn't run. Also I don't see the expected changes in |
I can add it back, but I figured its not required for the current PR feature-set/fixes and we could leave it out for a next PR. see #2105 (comment) |
To me to have all the "always true" changes together is more cohesive than only part of the changes for "always true" + enums fix. To summarize, it'd be best to have two PRs:
But I'm fine to have everything in this single PR. Thanks. |
3674e32
to
45bfbc9
Compare
lets see:
I am a bit lost, as I don't have an idea on how to move forwared here/what exactly needs to be done |
There's also:
|
ok, lets see how you like the latest iteration. I have worked thru all the mentioned rules. what a ride ;). I think there is no need to adjust |
thinking about this one might be doable: class ConditionalAlwaysTrue
{
public function doFoo(int $i, \stdClass $std)
{
if ($i > 0) {
} elseif ($std ? 'foo' : 'bar') { // always-true should not be reported because last condition
}
if ($i > 0) {
} elseif ($std ? 'foo' : 'bar') { // always-true should be reported, because another condition below
} elseif (rand(0,1)) {
}
}
} |
Please also add a test for phpstan/phpstan#8240, thanks. |
phpstan/phpstan#8240 is interessting. its not fixed by the PR as is. the problem is similar but different. |
This pull request has been marked as ready for review. |
cf13749
to
d6ad04c
Compare
518c546
to
8255fad
Compare
…eanType() using rules
b3f667e
to
f813e9e
Compare
Thank you! I have more improvements in mind, I started them already: 565fb0f |
cool. if you want me to work on more, just open a new issue and give me an idea what we are targeting :) |
To match the current feature set, we need something like |
Also there should be a tip about this config option when such error is reported. |
And also: There is some complicated logic in UnreachableIfBranchesRule which we should rethink for bleedingEdge, because when "always true" is always reported, we might not need another rule to say the same thing... |
implements the idea of #2095 (comment)
closes phpstan/phpstan#8042
closes phpstan/phpstan#8485
closes phpstan/phpstan#7721
closes phpstan/phpstan#4242
closes phpstan/phpstan#8240
re-implements #2095