Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8330 - take into account that static type may have been unwrapped in hasStaticInType() #8335

Merged
merged 1 commit into from Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -627,7 +627,7 @@ private static function getMethodReturnType(
*/
private static function hasStaticInType(Type\TypeNode $type): bool
{
if ($type instanceof TNamedObject && $type->value === 'static') {
if ($type instanceof TNamedObject && ($type->value === 'static' || $type->was_static)) {
return true;
}

Expand Down
27 changes: 27 additions & 0 deletions tests/Template/ClassTemplateTest.php
Expand Up @@ -3799,6 +3799,33 @@ final public static function create(): static
}
}',
],
'static is the return type of an analyzed static method' => [
'<?php

abstract class A
{
}

final class B extends A
{
public static function create(): static
{
return new self();
}
}

final class Service
{
public function do(): void
{
$this->acceptA(B::create());
}

private function acceptA(A $_a): void
{
}
}',
],
];
}

Expand Down