Skip to content

Commit

Permalink
stop failing when fetching using vars (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko authored Oct 14, 2024
1 parent c87c99a commit 75f4bea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Infer/SimpleTypeGetters/ClassConstFetchTypeGetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Infer/SimpleExpressionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 75f4bea

Please sign in to comment.