-
Notifications
You must be signed in to change notification settings - Fork 587
Narrow division to int when modulo is known to be zero #5757
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
Changes from 2 commits
c67de60
9024135
ebf4d35
c865717
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug9724; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| class HelloWorld | ||
| { | ||
| public function thisWorks(?int $limit, int $offset = 0): void | ||
| { | ||
| if ($limit && 0 === ($offset % $limit)) { | ||
| assertType('int', $offset / $limit); | ||
| assertType('int', ($offset / $limit) + 1); | ||
| } | ||
| } | ||
|
|
||
| public function thisDoesntWork(?int $limit, int $offset = 0): void | ||
| { | ||
| if ($limit && $offset && (0 === ($offset % $limit))) { | ||
| assertType('int<min, -1>|int<1, max>', $offset / $limit); | ||
| assertType('int<min, 0>|int<2, max>', ($offset / $limit) + 1); | ||
| } | ||
| } | ||
|
|
||
| /** @param int<-2, 2> $offsetRange */ | ||
| public function withRange(int $limit, int $offset, int $offsetRange): void | ||
| { | ||
| if ($limit) { | ||
| assertType('(float|int)', $offset / $limit); | ||
| assertType('float|int<-2, 2>', $offsetRange / $limit); | ||
| } | ||
| } | ||
|
|
||
| private function expectInt(int $page): void | ||
| { | ||
| } | ||
|
|
||
| public function originalIssue(?int $limit, int $offset = 0): void | ||
| { | ||
| if ($limit && $offset && (0 === ($offset % $limit))) { | ||
| $this->expectInt(($offset / $limit) + 1); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code needs to be analyzed by a RuleTest to proof it fixes the error reported in phpstan/phpstan#9724
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Added a |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.