Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 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
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,66 @@ | ||
<?php declare(strict_types = 1); // lint >= 8.0 | ||
|
||
namespace Bug6790; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
class Repository | ||
{ | ||
/** | ||
* @param array<T> $items | ||
*/ | ||
public function __construct(private array $items) {} | ||
|
||
/** | ||
* @return ?T | ||
*/ | ||
public function find(string $id) | ||
{ | ||
return $this->items[$id] ?? null; | ||
} | ||
} | ||
|
||
/** | ||
* @template T | ||
*/ | ||
class Repository2 | ||
{ | ||
/** | ||
* @param array<T> $items | ||
*/ | ||
public function __construct(private array $items) {} | ||
|
||
/** | ||
* @return T|null | ||
*/ | ||
public function find(string $id) | ||
{ | ||
return $this->items[$id] ?? null; | ||
} | ||
} | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param Repository<string> $r | ||
* @return void | ||
*/ | ||
public function doFoo(Repository $r): void | ||
{ | ||
assertType('string|null', $r->find('foo')); | ||
} | ||
|
||
/** | ||
* @param Repository2<string> $r | ||
* @return void | ||
*/ | ||
public function doFoo2(Repository2 $r): void | ||
{ | ||
assertType('string|null', $r->find('foo')); | ||
} | ||
|
||
} |