psalm
psalm copied to clipboard
False-positive `PropertyTypeCoercion` for `static` in trait if used in final class
https://psalm.dev/r/2cb05e09b4
The trait can be used in non-final and final classes, so I can't change static
to self
.
There should be no error in final class Baz
.
I found these snippets:
https://psalm.dev/r/2cb05e09b4
<?php
trait Foo {
/** @var static|null */
private static $instance;
static function foo(): void {
self::$instance = new static();
}
}
/** @psalm-consistent-constructor */
class Bar {
use Foo;
}
final class Baz {
use Foo;
}
Psalm output (using commit ef3b018):
ERROR: PropertyTypeCoercion - 8:24 - Baz::$instance expects 'Baz&static|null', parent type 'Baz' provided