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
InvalidPropertyAssignmentValue when using class, but not when using interfaces in templated array keys #3907
Labels
Comments
I found these snippets: https://psalm.dev/r/1ef3e94a1a<?php
class Foo {}
class Bar {}
/** @psalm-template O of ?(Foo|Bar) */
class Resolved
{
/**
* @var Foo|Bar
* @psalm-var O
*/
private $entity = null;
/**
* @psalm-param array{foo?: O, bar?: O} $qux
*/
public function __contruct(array $qux)
{
if (isset($qux['foo']) && $qux['foo'] instanceof Foo) {
$this->entity = $qux['foo'];
}
if (isset($qux['bar']) && $qux['bar'] instanceof Bar) {
$this->entity = $qux['bar'];
}
}
}
https://psalm.dev/r/dc6a46bdf2<?php
interface Foo {}
interface Bar {}
/** @psalm-template O of ?(Foo|Bar) */
class Resolved
{
/**
* @var Foo|Bar
* @psalm-var O
*/
private $entity = null;
/**
* @psalm-param array{foo?: O, bar?: O} $qux
*/
public function __contruct(array $qux)
{
if (isset($qux['foo']) && $qux['foo'] instanceof Foo) {
$this->entity = $qux['foo'];
}
if (isset($qux['bar']) && $qux['bar'] instanceof Bar) {
$this->entity = $qux['bar'];
}
}
}
https://psalm.dev/r/f7c663771f<?php
class Foo {}
interface Bar {}
/** @psalm-template O of ?(Foo|Bar) */
class Resolved
{
/**
* @var Foo|Bar
* @psalm-var O
*/
private $entity = null;
/**
* @psalm-param array{foo?: O, bar?: O} $qux
*/
public function __contruct(array $qux)
{
if (isset($qux['foo']) && $qux['foo'] instanceof Foo) {
$this->entity = $qux['foo'];
}
if (isset($qux['bar']) && $qux['bar'] instanceof Bar) {
$this->entity = $qux['bar'];
}
}
}
|
That's a bug, simplified to https://psalm.dev/r/22d9bce02f |
I found these snippets: https://psalm.dev/r/22d9bce02f<?php
class Foo {}
class Bar {}
/** @template FooOrBarOrNull of Foo|Bar|null */
class Resolved
{
/**
* @var FooOrBarOrNull
*/
private $entity = null;
/**
* @psalm-param FooOrBarOrNull $qux
*/
public function __contruct(?object $qux)
{
if ($qux instanceof Foo) {
$this->entity = $qux;
}
}
}
|
Thank you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ERROR: https://psalm.dev/r/1ef3e94a1a
OK: https://psalm.dev/r/dc6a46bdf2
If using an interface for one and a class for the other only the class one fails: https://psalm.dev/r/f7c663771f
Is this some bug or am I missing something here?
The text was updated successfully, but these errors were encountered: