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

Psalm is unable to detect type of object shape when trying to call callable property. #10970

Open
rzvc opened this issue May 11, 2024 · 1 comment

Comments

@rzvc
Copy link

rzvc commented May 11, 2024

Code exemplifying the issue:
https://psalm.dev/r/600aad3b9e

Works with array shapes:
https://psalm.dev/r/ae6c3fa3c0

Copy link

I found these snippets:

https://psalm.dev/r/600aad3b9e
<?php
/**
 * @psalm-type CallableShape = object{
 * 	foo : string,
 *  bar : callable(): int,
 * }
 *
 * @psalm-suppress MissingConstructor 
 */
class Test
{
    /** @var CallableShape */
    public $foo;
}

$t = new Test();

$t->foo->bar();
Psalm output (using commit 16b24bd):

INFO: MixedMethodCall - 18:10 - Cannot determine the type of $t->foo when calling method bar
https://psalm.dev/r/ae6c3fa3c0
<?php
/**
 * @psalm-type CallableShape = array{
 * 	foo : string,
 *  bar : callable(): int,
 * }
 *
 * @psalm-suppress MissingConstructor 
 */
class Test
{
    /** @var CallableShape */
    public $foo;
}

$t = new Test();

$t->foo['bar']();
Psalm output (using commit 16b24bd):

No issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant