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

Fix bug 8937 with match and treatPhpDocTypesAsCertain #2250

Merged
merged 2 commits into from
Apr 6, 2023

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Feb 22, 2023

Closes phpstan/phpstan#8937

I dunno if it's the best fix, but seems like it's solving both phpstan/phpstan#8932 and phpstan/phpstan#8937.

@@ -65,13 +66,23 @@ public function processNode(Node $node, Scope $scope): array
$matchCondition,
$armCondition->getCondition(),
);
$armConditionResult = ($this->treatPhpDocTypesAsCertain ? $armConditionScope->getType($armConditionExpr) : $armConditionScope->getNativeType($armConditionExpr));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I split this in nextArmIsDeadForType and nextArmIsDeadForNativeType because

  • Match arm is unreachable should rely on $nextArmIsDeadForNativeType || $nextArmIsDeadForType && $this->treatPhpDocTypesAsCertain in order to not be reported in the issue 8932.
  • Match expression does not handle remaining should rely only on nextArmIsDeadForType in order to not be reported in the issue 8937.

This way extra checks are allowed when using treatPhpDocTypesAsCertain: false, but phpstan are not complaining if they are missing.

$errors = [];
$armsCount = count($node->getArms());
$hasDefault = false;
foreach ($node->getArms() as $i => $arm) {
if ($nextArmIsDead) {
if ($nextArmIsDeadForNativeType || $nextArmIsDeadForType && $this->treatPhpDocTypesAsCertain) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use parentheses to disambiguate the condition. And please rebase on top of 1.10.x so we can see whether there are new failures. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's rebased with parentheses added

@ondrejmirtes ondrejmirtes merged commit 3be609e into phpstan:1.10.x Apr 6, 2023
373 of 377 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants