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

More precise MixedType::toBoolean() with subtracted type #3471

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 23, 2024

I now understood why my previous test was not failling and was able to apply the suggested fix

followup to #3421

@@ -53,4 +53,9 @@ function subtract(mixed $m, $moreThenFalsy) {
assertType('mixed', $m);
assertType('bool', (bool) $m); // could be true
}

if ($m != 0 && !is_array($m) && $m != null && !is_object($m)) { // subtract more types then falsy
Copy link
Contributor Author

@staabm staabm Sep 23, 2024

Choose a reason for hiding this comment

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

the test in the above if (line 52) is still not able to narrow the type, but I think its related to that we compare 2 variables.

when comparing against literals - as we do in the new test - we at least were able to trigger the bug in the previous StaticTypeFactory::falsey()->equals($this->subtractedType) logic

@ondrejmirtes ondrejmirtes merged commit 9f13233 into phpstan:1.12.x Sep 26, 2024
482 of 499 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the more-then-falsy branch September 26, 2024 07:55
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.

None yet

2 participants