-
Notifications
You must be signed in to change notification settings - Fork 666
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 loses the type of typed static properties #11180
Comments
I found these snippets: https://psalm.dev/r/588d62ba8f<?php declare(strict_types=1);
final class StaticClass
{
public static string $property = '';
public function testMethod(): void {
if (StaticClass::$property === '') {
return;
}
/** @psalm-trace StaticClass::$property */
}
}
final class TestClass
{
public function testMethod(): void {
if (StaticClass::$property === '') {
return;
}
/** @psalm-trace StaticClass::$property */
}
}
function test_function(): void {
if (StaticClass::$property === '') {
return;
}
/** @psalm-trace StaticClass::$property */
}
|
If I understand the explanation in #7173 correctly, psalm-trace only works with variables in the current scope. So the type is known if you assign it to a variable. Do you experience an issue not involving psalm-trace? |
I found these snippets: https://psalm.dev/r/e195b49aa9<?php declare(strict_types=1);
final class StaticClass
{
public static string $property = '';
public function testMethod(): void {
$x = StaticClass::$property;
if ($x === '') {
return;
}
/** @psalm-trace $x */
}
}
final class TestClass
{
public function testMethod(): void {
$y = StaticClass::$property;
if ($y === '') {
return;
}
/** @psalm-trace $y*/
}
}
function test_function(): void {
$z = StaticClass::$property;
if ($z === '') {
return;
}
/** @psalm-trace $z */
}
|
This does indeed not work. |
I found these snippets: https://psalm.dev/r/9e05ac200d<?php declare(strict_types=1);
final class StaticClass
{
public static string $property = '';
public function testMethod(): void {
if (StaticClass::$property === '') {
return;
}
$_x = StaticClass::$property;
/** @psalm-trace $_x */
}
}
final class TestClass
{
public function testMethod(): void {
if (StaticClass::$property === '') {
return;
}
$_y = StaticClass::$property;
/** @psalm-trace $_y*/
}
}
function test_function(): void {
if (StaticClass::$property === '') {
return;
}
$_z = StaticClass::$property;
/** @psalm-trace $_z */
}
|
https://psalm.dev/r/79e5a054b0 And also that a look at the Psalm baseline here: phpmyadmin/phpmyadmin#19440 |
I found these snippets: https://psalm.dev/r/79e5a054b0<?php declare(strict_types=1);
final class StaticClass
{
public static string $property = '';
}
final class TestClass
{
public function foo(): void
{
if (StaticClass::$property === '') {
return;
}
$this->bar(StaticClass::$property);
}
private function bar(string $value): void
{
echo $value;
}
}
|
Psalm does not know the type of a typed static property of another class. It assumes it's
mixed
when it's not.https://psalm.dev/r/588d62ba8f
Maybe related to #7173.
The text was updated successfully, but these errors were encountered: