Skip to content

Commit 1116e03

Browse files
committed
Fix internal error when accessing enum case by class-string
1 parent e689e1b commit 1116e03

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,13 @@ function (Type $type, callable $traverse): Type {
18581858
);
18591859
}
18601860

1861+
if ($constantClassType->isClassStringType()->yes()) {
1862+
if ($constantClassType->isConstantScalarValue()->yes()) {
1863+
$isObject = false;
1864+
}
1865+
$constantClassType = $constantClassType->getClassStringObjectType();
1866+
}
1867+
18611868
$types = [];
18621869
foreach ($constantClassType->getObjectClassNames() as $referencedClass) {
18631870
if (!$this->getReflectionProvider()->hasClass($referencedClass)) {

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,16 @@ public function testBug10772(): void
13381338
$this->assertNoErrors($errors);
13391339
}
13401340

1341+
public function testBug10985(): void
1342+
{
1343+
if (PHP_VERSION_ID < 80100) {
1344+
$this->markTestSkipped('Test requires PHP 8.1.');
1345+
}
1346+
1347+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-10985.php');
1348+
$this->assertNoErrors($errors);
1349+
}
1350+
13411351
public function testBug10979(): void
13421352
{
13431353
if (PHP_VERSION_ID < 80100) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug10985;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
enum Test {
8+
case ORIGINAL;
9+
}
10+
11+
function (): void {
12+
$item = Test::class;
13+
$result = ($item)::ORIGINAL;
14+
assertType('Bug10985\\Test::ORIGINAL', $result);
15+
};

0 commit comments

Comments
 (0)