-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix native type of array after
array_push()
Closes phpstan/phpstan#9403
- Loading branch information
1 parent
903ffc6
commit 564f79f
Showing
5 changed files
with
158 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Bug9403; | ||
|
||
use function PHPStan\Testing\assertNativeType; | ||
use function PHPStan\Testing\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
|
||
/** | ||
* @param int $max | ||
* @return int[] | ||
*/ | ||
public function testMe(int $max): array | ||
{ | ||
$result = []; | ||
for ($i = 0; $i < $max; $i++) { | ||
array_push($result, $i); | ||
} | ||
|
||
assertType('list<int<0, max>>', $result); | ||
assertNativeType('list<int<0, max>>', $result); | ||
|
||
if (!empty($result)) { | ||
rsort($result); | ||
} | ||
return $result; | ||
} | ||
|
||
} |
564f79f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when reading the commit title and seeing the big red diff block, I already thought you simplified the crazy logic for array_push :P
564f79f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have done that in two commits really. The only significant change is that I was able to do:
And pass that into
assignExpression
.