psalm
psalm copied to clipboard
Psalm is unable to detect type of object shape when trying to call callable property.
Code exemplifying the issue: https://psalm.dev/r/600aad3b9e
Works with array shapes: https://psalm.dev/r/ae6c3fa3c0
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!