-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wrongly convertion of list<T> to array{T}
- Loading branch information
1 parent
3592cf0
commit b3c99fb
Showing
2 changed files
with
46 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug11642; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Repository | ||
{ | ||
/** | ||
* @psalm-param array<string|int, mixed> $criteria | ||
* | ||
* @return object[] The objects. | ||
* @psalm-return list<\stdClass> | ||
*/ | ||
function findBy(array $criteria): array | ||
{ | ||
return [new \stdClass, new \stdCLass, new \stdClass, new \stdClass]; | ||
} | ||
} | ||
|
||
class Payload { | ||
/** @var non-empty-list<string> */ | ||
public array $ids = ['one', 'two']; | ||
} | ||
|
||
function doFoo() { | ||
$payload = new Payload(); | ||
|
||
$fetcher = new Repository(); | ||
$entries = $fetcher->findBy($payload->ids); | ||
assertType('list<stdClass>', $entries); | ||
assertType('int<0, max>', count($entries)); | ||
assertType('int<1, max>', count($payload->ids)); | ||
if (count($entries) !== count($payload->ids)) { | ||
exit(); | ||
} | ||
|
||
assertType('non-empty-list<stdClass>', $entries); | ||
if (count($entries) > 3) { | ||
throw new \RuntimeException(); | ||
} | ||
|
||
assertType('non-empty-list<stdClass>', $entries); | ||
} |