Skip to content

Commit

Permalink
Fixed static resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Sep 21, 2023
1 parent dc0ebe0 commit 900645a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/Reflector/PhpParserReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,13 @@ private function reflectNativeType(?Node $node): ?Type\Type
}

if ($node instanceof Name) {
return types::object($this->nameContext->resolveNameAsClass($node->toCodeString()));
$resolvedName = $this->nameContext->resolveNameAsClass($node->toCodeString());

if ($node->toString() === 'static') {
return types::static($resolvedName);
}

return types::object($resolvedName);
}

throw new ReflectionException(sprintf('%s is not supported.', $node::class));
Expand Down
2 changes: 1 addition & 1 deletion src/TypeResolver/ClassTemplateResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function visitNamedObject(Type\NamedObjectType $type): mixed
public function visitStatic(Type\StaticType $type): mixed
{
/** @psalm-suppress ImpureFunctionCall */
return types::object($type->declaringClass, ...array_map(
return types::static($type->declaringClass, ...array_map(
fn (Type\Type $type): Type\Type => $type->accept($this),
$type->templateArguments,
));
Expand Down
6 changes: 2 additions & 4 deletions src/TypeResolver/StaticResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,10 @@ public function visitNamedObject(Type\NamedObjectType $type): mixed
public function visitStatic(Type\StaticType $type): mixed
{
/** @psalm-suppress ImpureFunctionCall */
$templateArguments = array_map(
return types::object($this->class, ...array_map(
fn (Type\Type $type): Type\Type => $type->accept($this),
$type->templateArguments,
);

return types::object($this->class, ...$templateArguments);
));
}

public function visitObject(Type\ObjectType $type): mixed
Expand Down

0 comments on commit 900645a

Please sign in to comment.