Skip to content

Broken assert for array and list - DocblockTypeContradiction #9037

@kkmuffme

Description

@kkmuffme

https://psalm.dev/r/ea9ecf75b9

As we see in line 20, psalm correctly infers that $foo can be type list when checking with array_values

When using a custom assert function, it correctly asserts it, but reports a false positive DocblockTypeContradiction on the if condition in line 23

What actually happens here is, that it assumes that @psalm-assert type array<string, string> does not contain list<string> which is correct - however why does it report this as a DocblockTypeContradiction in the place where the function is called?

How can I assert if true => list<string>, if false => array<string, string>?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions