Skip to content

Fixed integer range minus bugs#690

Merged
ondrejmirtes merged 10 commits intophpstan:masterfrom
staabm:minus-range-bugs
Oct 5, 2021
Merged

Fixed integer range minus bugs#690
ondrejmirtes merged 10 commits intophpstan:masterfrom
staabm:minus-range-bugs

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Sep 27, 2021

Fixes Integer-Range-Minus bugs mentioned in phpstan/phpstan#5614

assertType('int<5, 100>', $r1 * $r2);
assertType('float|int<0, 1>', $r1 / $r2);

assertType('int<-99, 19>', $r1 - $r3);
Copy link
Copy Markdown
Contributor Author

@staabm staabm Sep 27, 2021

Choose a reason for hiding this comment

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

this line is covering https://phpstan.org/r/0f2bf43b-e5a6-436b-ac44-e62a2c60ae94 from "Wrong inference with Minus" of phpstan/phpstan#5614


assertType('int<6, 20>', $r1 + $r2);
assertType('int<-4, 0>', $r1 - $r2);
assertType('int<-9, 5>', $r1 - $r2);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

assertType('float|int<min, 2>', $r1 / $rMin);
assertType('int<min, 15>', $rMin + $r1);
assertType('int<min, -5>', $rMin - $r1);
assertType('int<-5, max>', $rMin - $r1);
Copy link
Copy Markdown
Contributor Author

@staabm staabm Sep 27, 2021

Choose a reason for hiding this comment

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

assertType('float|int<0, max>', $r1 / $rMax);
assertType('int<6, max>', $rMax + $r1);
assertType('int<4, max>', $rMax - $r1);
assertType('int<-5, max>', $rMax - $r1);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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


assertType('int<-10, 10>', $rangeFiveBoth + $rangeFiveBoth);
assertType('0', $rangeFiveBoth - $rangeFiveBoth);
assertType('int<-10, 10>', $rangeFiveBoth - $rangeFiveBoth);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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


assertType('int<min, 10>', $rangeFiveRight + $rangeFiveBoth);
assertType('int<min, 0>', $rangeFiveRight - $rangeFiveBoth);
assertType('int<0, max>', $rangeFiveRight - $rangeFiveBoth);
Copy link
Copy Markdown
Contributor Author

@staabm staabm Sep 27, 2021

Choose a reason for hiding this comment

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


assertType('int<-10, max>', $rangeFiveLeft + $rangeFiveBoth);
assertType('int<0, max>', $rangeFiveLeft - $rangeFiveBoth);
assertType('int<-10, max>', $rangeFiveLeft - $rangeFiveBoth);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@staabm staabm marked this pull request as ready for review September 27, 2021 15:19
@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Sep 27, 2021

should be good to go. remaining test-errors are unrelated.

//cc @orklah

@staabm staabm marked this pull request as draft September 27, 2021 16:17
@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Sep 27, 2021

Note the -∞ instead of ∞

oh, I need to double check the new expectations..


assertType('int<min, 10>', $rangeFiveRight + $rangeFiveBoth);
assertType('int<min, 0>', $rangeFiveRight - $rangeFiveBoth);
assertType('int<min, 10>', $rangeFiveRight - $rangeFiveBoth);
Copy link
Copy Markdown
Contributor Author

@staabm staabm Sep 28, 2021

Choose a reason for hiding this comment

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

assertType('float|int<min, 2>', $r1 / $rMin);
assertType('int<min, 15>', $rMin + $r1);
assertType('int<min, -5>', $rMin - $r1);
assertType('int<min, 4>', $rMin - $r1);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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


assertType('int<min, 10>', $rangeFiveBoth + $rangeFiveRight);
assertType('int<min, 0>', $rangeFiveBoth - $rangeFiveRight);
assertType('int<-10, max>', $rangeFiveBoth - $rangeFiveRight);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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


assertType('int<min, 15>', $r1 + $rMin);
assertType('int<min, 5>', $r1 - $rMin);
assertType('int<-4, max>', $r1 - $rMin);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@staabm staabm marked this pull request as ready for review September 28, 2021 11:47
@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Sep 28, 2021

now for real - should be good to go. remaining test-errors are unrelated.

@ondrejmirtes ondrejmirtes merged commit d365eff into phpstan:master Oct 5, 2021
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@staabm staabm deleted the minus-range-bugs branch October 5, 2021 14:02
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.

3 participants