-
Notifications
You must be signed in to change notification settings - Fork 672
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
Psalm don't determine type of object after instanceof
with class-string<CLASS>
#6499
Labels
Comments
I found these snippets: https://psalm.dev/r/7e3853aa3c<?php
class X {
public function run(): void {
}
}
final class Y {
/**
* @psalm-param class-string<X> $class
*/
public function __construct(
private string $class,
) {}
public function go(object $object): void {
if (!$object instanceof $this->class) {
throw new Exception;
}
$object->run();
}
}
|
simpler reproducer: |
I found these snippets: https://psalm.dev/r/e11cdd8900<?php
final class Y {
/**
* @psalm-var class-string<stdClass> $class
*/
private string $class;
public function go(object $object): void {
$a = $this->class;
/** @psalm-trace $a */;
if ($object instanceof $a) {
/** @psalm-trace $object */; // doesn't works
}
$b = stdClass::class;
/** @psalm-trace $b */;
if ($object instanceof $b) {
/** @psalm-trace $object */; // works
}
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://psalm.dev/r/7e3853aa3c
The text was updated successfully, but these errors were encountered: