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
Callable type information is not preserved in class constants #5743
Comments
I found these snippets: https://psalm.dev/r/ac4c096eb4<?php
class a {
/** @var list<callable(mixed): bool> */
public const a = ['is_array', 'is_int'];
}
$a = a::a;
/** @psalm-trace $a */;
$res = $a[0]();
/** @psalm-trace $res */;
|
It's actually worse than that. I think @var doesn't work at all above a constant: |
I found these snippets: https://psalm.dev/r/6e0994afa7<?php
class a {
/** @var bool */
public const a = ['is_array', 'is_int'];
}
$a = a::a;
/** @psalm-trace $a */;
$res = $a[0]();
/** @psalm-trace $res */;
|
Closing this as a duplicate of #942 |
@AndrolGenhald I'm surprised this was not fixed though. Is there something special here? |
We don't currently resolve literal strings to callables: https://psalm.dev/r/13a7a514f3. Not sure if that's an intentional choice or not. It would also be fixed if we add some way to force the |
I found these snippets: https://psalm.dev/r/13a7a514f3<?php
$callable = "is_array";
$test = $callable([]);
/** @psalm-trace $test */;
|
Oh yeah, right, forgot the inferred type has priority |
Opened #7547. |
Same issue also for regular constants: https://psalm.dev/r/53d81047a5 |
I found these snippets: https://psalm.dev/r/53d81047a5<?php
if ( defined( 'FOO' ) && is_int( FOO ) ) {
$a = FOO;
/** @psalm-trace $a */;
}
|
See https://psalm.dev/r/ac4c096eb4
The text was updated successfully, but these errors were encountered: