psalm icon indicating copy to clipboard operation
psalm copied to clipboard

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

Open rzvc opened this issue 1 year ago • 1 comments

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

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

rzvc avatar May 11 '24 02:05 rzvc

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!

psalm-github-bot[bot] avatar May 11 '24 02:05 psalm-github-bot[bot]