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
False positive when comparing ReflectionNamedType::getName() with 'static' #8167
Comments
I found these snippets: https://psalm.dev/r/2c06d6b1d3<?php
namespace Test;
class Foo {
public function bar(): static {
return $this;
}
}
$class = new \ReflectionClass(Foo::class);
$method = $class->getMethod('bar');
$returnType = $method->getReturnType();
if ($returnType instanceof \ReflectionNamedType) {
if (! $returnType->isBuiltin() && $returnType->getName() !== 'static') {
}
}
|
Looks to me like the assertion in the stub needs changed from |
@AndrolGenhald Good point about I don't see any other possible return value, so I couldn't find where the return type is documented, it's not in the CallMap at least. Because the result is dependent on whether |
It's in |
@AndrolGenhald TIL, thanks! Fixed in #8201. |
When
ReflectionNamedType::isBuiltin()
returnsfalse
, Psalm assumes thatgetName()
returns aclass-string
:Demo: https://psalm.dev/r/2c06d6b1d3
Even though
'static'
is also a valid return type since PHP 8.0: https://3v4l.org/ZAqYKThe text was updated successfully, but these errors were encountered: