-
Notifications
You must be signed in to change notification settings - Fork 668
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 positives in the function forward_static_call_array #10461
Comments
I found these snippets: https://psalm.dev/r/ecc7244555<?php
/** @return class-string */
function getClassName(object $class): string {
return $class::class;
};
function fromArrays(array $data, object $object)
{
$className = getClassName($object);
return forward_static_call_array([$className, 'from'], $data);
}
|
we don't know if there's a method named The latter issue is a useful safeguard as lists work for every PHP version, but string-keyed arrays need to match the signature (and Psalm doesn't seem to be able to infer it): https://3v4l.org/LvpJt |
That's true, but if we pass type |
That's the thing with callables - they are only callable if they can be called. Otherwise, they are just arrays / strings. With that said, this should work (but doesn't): https://psalm.dev/r/a1bdbc0e6b |
I found these snippets: https://psalm.dev/r/a1bdbc0e6b<?php
/** @return class-string */
function getClassName(object $class): string {
return $class::class;
};
/** @param list $data */
function fromArrays(array $data, object $object): mixed
{
$className = getClassName($object);
$callback = [$className, 'from'];
if (!is_callable($callback)) {
throw new RuntimeException('bad callable');
}
/** @psalm-trace $callback */;
return forward_static_call_array($callback, $data);
}
|
Isn't this code not invalid in the first place anyway, since
This also produces a fatal error when run in PHP, doesn't it? |
I found these snippets: https://psalm.dev/r/a1bdbc0e6b<?php
/** @return class-string */
function getClassName(object $class): string {
return $class::class;
};
/** @param list $data */
function fromArrays(array $data, object $object): mixed
{
$className = getClassName($object);
$callback = [$className, 'from'];
if (!is_callable($callback)) {
throw new RuntimeException('bad callable');
}
/** @psalm-trace $callback */;
return forward_static_call_array($callback, $data);
}
|
No, it works just fine: https://3v4l.org/lTQWQ |
Ah, I mixed it up with state:
But apparently |
🤷♂️ I was confused by that passage in the docs too. |
Hello,
The following code produces two false positives
https://psalm.dev/r/ecc7244555
We know that the variable passed to
forward_static_call_array
is a class string, so it should be treated as a callable.The text was updated successfully, but these errors were encountered: