diff --git a/src/Infer/SimpleTypeGetters/ClassConstFetchTypeGetter.php b/src/Infer/SimpleTypeGetters/ClassConstFetchTypeGetter.php index 4edfe62c..5d9e0ae1 100644 --- a/src/Infer/SimpleTypeGetters/ClassConstFetchTypeGetter.php +++ b/src/Infer/SimpleTypeGetters/ClassConstFetchTypeGetter.php @@ -17,7 +17,7 @@ class ClassConstFetchTypeGetter { public function __invoke(Node\Expr\ClassConstFetch $node, Scope $scope): Type { - if ($node->name->toString() === 'class') { + if ($node->name instanceof Node\Identifier && $node->name->toString() === 'class') { if ($node->class instanceof Node\Name) { return new LiteralStringType($node->class->toString()); } @@ -45,7 +45,7 @@ public function __invoke(Node\Expr\ClassConstFetch $node, Scope $scope): Type // In case we're here, it means that we were unable to infer the type from the const fetch. So we rollback to the // string type. - if ($node->name->toString() === 'class') { + if ($node->name instanceof Node\Identifier && $node->name->toString() === 'class') { return new StringType; } diff --git a/tests/Infer/SimpleExpressionsTest.php b/tests/Infer/SimpleExpressionsTest.php index a2de919e..715769e2 100644 --- a/tests/Infer/SimpleExpressionsTest.php +++ b/tests/Infer/SimpleExpressionsTest.php @@ -20,6 +20,13 @@ ['!! $some', 'boolean'], ]); +it( + 'doesnt fail on dynamic static fetch', + fn ($statement, $expectedType) => expect(getStatementType($statement)->toString())->toBe($expectedType), +)->with([ + ['Something::{$v}', 'unknown'], +]); + // @todo // casts test (int, float, bool, string) // array with literals test (int, float, bool, string)