-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix generalization of EnumCaseObjectType
- Loading branch information
1 parent
73f14db
commit 9e42896
Showing
3 changed files
with
69 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php // lint >= 8.1 | ||
|
||
namespace Bug6695; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
enum Foo: int | ||
{ | ||
case BAR = 1; | ||
case BAZ = 2; | ||
|
||
public function toCollection(): void | ||
{ | ||
assertType('Bug6695\Collection<int, Bug6695\Foo>', $this->collect(self::cases())); | ||
} | ||
|
||
/** | ||
* Create a collection from the given value. | ||
* | ||
* @template TKey of array-key | ||
* @template TValue | ||
* | ||
* @param iterable<TKey, TValue> $value | ||
* @return Collection<TKey, TValue> | ||
*/ | ||
function collect($value): Collection | ||
{ | ||
return new Collection($value); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @template TKey of array-key | ||
* @template TValue | ||
* | ||
*/ | ||
class Collection | ||
{ | ||
|
||
/** | ||
* The items contained in the collection. | ||
* | ||
* @var iterable<TKey, TValue> | ||
*/ | ||
protected $items = []; | ||
|
||
/** | ||
* Create a new collection. | ||
* | ||
* @param iterable<TKey, TValue> $items | ||
* @return void | ||
*/ | ||
public function __construct($items = []) | ||
{ | ||
$this->items = $items; | ||
} | ||
} |