-
Notifications
You must be signed in to change notification settings - Fork 428
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
Union of enum cases accepts the enum class type with negated cases #2418
Conversation
Instead of changing what |
@ondrejmirtes |
81c1d20
to
d9d9ddf
Compare
2574f70
to
f887b3c
Compare
This pull request has been marked as ready for review. |
tests/PHPStan/Type/UnionTypeTest.php
Outdated
@@ -1186,6 +1188,72 @@ public function dataAccepts(): array | |||
], | |||
|
|||
]; | |||
|
|||
if (PHP_VERSION_ID < 80100) { | |||
return; |
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.
It's a bit tricky to mark the rest of the dataProvider as tested only on PHP 8.1. Please reverse the condition and put the enum yield
s into that condition:
if (PHP_VERSION_ID >= 80100) {
yield...
}
If PHPCS complains, move one existing yield below the condition.
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.
I reversed the condition and moved some of the existing yields.
tests/PHPStan/Type/UnionTypeTest.php
Outdated
]), | ||
new ObjectType( | ||
'PHPStan\Fixture\TestEnum', | ||
new EnumCaseObjectType('PHPStan\Fixture\TestEnum', 'TWO'), |
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.
One more test please:
yield [
new UnionType([
new EnumCaseObjectType('PHPStan\Fixture\TestEnum', 'ONE'),
new NullType(),
]),
new UnionType([
new ObjectType(
'PHPStan\Fixture\TestEnum',
new EnumCaseObjectType('PHPStan\Fixture\TestEnum', 'TWO'),
),
new NullType(),
]),
TrinaryLogic::createYes(),
);
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.
I added this test case.
@ondrejmirtes |
Alright, one more thing: you're trying to fix phpstan/phpstan#8846. Which means we need a regression test in the test class for the rule that reports the false positive. Which means you should write a test in Functions\ReturnTypeRuleTest. And make sure it fails without your changes in |
Perfect, thank you! |
This PR changes the result of removing an enum case from its class.
TestEnum~TestEnum::A
TestEnum::B|TestEnum::C
Closes phpstan/phpstan#8846