Skip to content

Commit

Permalink
add test for issue 7162
Browse files Browse the repository at this point in the history
  • Loading branch information
schlndh committed Nov 16, 2023
1 parent f54bcec commit 0143307
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/generic-class-string.php');
if (PHP_VERSION_ID >= 80100) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/generic-enum-class-string.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7162.php');
}

require_once __DIR__ . '/data/generic-generalization.php';
Expand Down
35 changes: 35 additions & 0 deletions tests/PHPStan/Analyser/data/bug-7162.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1); // lint >= 8.1

namespace Bug7162;

use function PHPStan\Testing\assertType;

class HelloWorld
{

/**
* @param class-string<\BackedEnum> $enumClassString
*/
public static function casesWithLabel(string $enumClassString): void
{
foreach ($enumClassString::cases() as $unitEnum) {
assertType('BackedEnum', $unitEnum);
}
}
}

enum Test{
case ONE;
}

/**
* @phpstan-template TEnum of \UnitEnum
* @phpstan-param TEnum $case
*/
function dumpCases(\UnitEnum $case) : void{
assertType('array<TEnum of UnitEnum (function Bug7162\\dumpCases(), argument)>', $case::cases());
}

function dumpCases2(Test $case) : void{
assertType('array{Bug7162\\Test::ONE}', $case::cases());
}

0 comments on commit 0143307

Please sign in to comment.