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

support unary-minus on IntegerRangeType #669

Merged
merged 4 commits into from
Sep 12, 2021

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 12, 2021

@staabm staabm marked this pull request as ready for review September 12, 2021 08:57
@staabm
Copy link
Contributor Author

staabm commented Sep 12, 2021

failling test is unrelated. just rebased.

if ($type instanceof IntegerRangeType) {
$negativeRange = $this->resolveType(new Node\Expr\BinaryOp\Mul($node->expr, new LNumber(-1)));

if ( $negativeRange instanceof IntegerRangeType && ($negativeRange->getMin() === null || $negativeRange->getMax() === null)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I was not sure whether multiplication by -1 should have already returned the range as we need it and this if-case actually compensates a bug in the Mul logic?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know, you tell me :) Feel free to fix more bugs here.

Copy link
Contributor Author

@staabm staabm Sep 12, 2021

Choose a reason for hiding this comment

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

Do we expect -$b === $b * -1 Given $b = int<min, 5> ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like it. Here's a small script I made to generate equations for Wolfram: https://3v4l.org/AUHH7

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix in #670

Copy link
Contributor Author

@staabm staabm Sep 13, 2021

Choose a reason for hiding this comment

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

btw: the same is true for division: Wolfram

@staabm
Copy link
Contributor Author

staabm commented Sep 12, 2021

@ondrejmirtes we can merge here as is. The multiplication bug will be fixed separately

@ondrejmirtes ondrejmirtes merged commit 33af274 into phpstan:master Sep 12, 2021
@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
4 participants