Skip to content
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

Invalid array callable wont get detected #6085

Closed
boesing opened this issue Jul 13, 2021 · 3 comments · Fixed by #10370
Closed

Invalid array callable wont get detected #6085

boesing opened this issue Jul 13, 2021 · 3 comments · Fixed by #10370

Comments

@boesing
Copy link
Contributor

boesing commented Jul 13, 2021

Hey there,

an array-callable must consist of "object"/"class name" and "method/static method" information. Any other information leads to runtime issues:

https://psalm.dev/r/b661a0cb84
https://3v4l.org/rE02P

If you triage this bug, please let me know how to help.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/b661a0cb84
<?php

function foo(callable $callback): void
{
    $callback();
}


final class Bar
{
    public static function baz(): void
    {}
}

foo([Bar::class, 'baz', 1231233]);
Psalm output (using commit 6729f4d):

No issues!

@orklah
Copy link
Collaborator

orklah commented Jul 13, 2021

Seems like a bundle of issues here
This is correctly flagged: https://psalm.dev/r/920f2bc3fa
But this is not: https://psalm.dev/r/88142fd37c
Ideally, $a in this example https://psalm.dev/r/69df2d109b should become callable-array{0: Bar::class, 1: "baz"}

I guess if I had to look at it, I'd start checking the first example and see how Psalm manage to flag the error (and where it comes from with --debug-emitted-issues) and then, I'd try to implement the same check when calling a Function or Method that has a callable parameter

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/920f2bc3fa
<?php


final class Bar
{
    public static function baz(): void
    {}
}
$a = [Bar::class, 'baz', 1231233];
assert(is_callable($a));
Psalm output (using commit 6729f4d):

ERROR: TypeDoesNotContainType - 10:1 - Type array{Bar::class, "baz", 1231233} for $a is never callable
https://psalm.dev/r/88142fd37c
<?php


final class Bar
{
    public static function baz(): void
    {}
}

assert(is_callable([Bar::class, 'baz', 1231233]));
Psalm output (using commit 6729f4d):

No issues!
https://psalm.dev/r/69df2d109b
<?php
function foo(callable $callback): void
{
    $callback();
}

final class Bar
{
    public static function baz(): void
    {}
}

$a = [Bar::class, 'baz'];
foo($a);
/** @psalm-trace $a */
Psalm output (using commit 6729f4d):

INFO: Trace - 15:23 - $a: array{Bar::class, "baz"}

kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 15, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 15, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 15, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 15, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 15, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 15, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 16, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 16, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 16, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 16, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 18, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants