psalm
psalm copied to clipboard
false positive InvalidPropertyAssignmentValue for templated arrays with named keys
https://psalm.dev/r/6325c38df8
I found these snippets:
https://psalm.dev/r/6325c38df8
<?php declare(strict_types=1);
/** @template TValue */
trait A
{
/** @psalm-var callable(): array{0: TValue} */
private $foo;
/**
* @psalm-param callable(): array{0: TValue} $foo
*/
public function __construct(callable $foo)
{
$this->foo = $foo;
}
}
/** @template TValue of object */
class B
{
/** @use A<TValue> */
use A;
}
Psalm output (using commit 6f28ee6):
ERROR: InvalidPropertyAssignmentValue - 14:22 - $this->foo with declared type 'callable():array{0: object}' cannot be assigned type 'callable():array{0: TValue:A as mixed}'
@GrandLTU , Not sure if I correct or not but I noticed you are using union types in incorrect manner. Check if it makes sense: https://psalm.dev/r/fbe1f7665b
I found these snippets:
https://psalm.dev/r/fbe1f7665b
<?php declare(strict_types=1);
/** @template TValue
* @template ReturnT array{0: TValue}
*/
trait A
{
/** @psalm-var Closure():ReturnT */
private $foo;
/**
* @psalm-param Closure():ReturnT $foo
*/
public function __construct(callable $foo)
{
$this->foo = $foo;
}
}
/**
* @template TValue of object
* @template ReturnInt of array{0: int}
*/
class B
{
/** @use A<TValue, ReturnInt> */
use A;
}
Psalm output (using commit 6f28ee6):
No issues!
@GrandLTU , Not sure if I correct or not but I noticed you are using union types in incorrect manner. Check if it makes sense: https://psalm.dev/r/fbe1f7665b
why is it incorrect?
I found these snippets:
https://psalm.dev/r/fbe1f7665b
<?php declare(strict_types=1);
/** @template TValue
* @template ReturnT array{0: TValue}
*/
trait A
{
/** @psalm-var Closure():ReturnT */
private $foo;
/**
* @psalm-param Closure():ReturnT $foo
*/
public function __construct(callable $foo)
{
$this->foo = $foo;
}
}
/**
* @template TValue of object
* @template ReturnInt of array{0: int}
*/
class B
{
/** @use A<TValue, ReturnInt> */
use A;
}
Psalm output (using commit 5ef82b5):
No issues!