Skip to content

Misused Psalm Assertion for isValid() method? #478

@likeajohny

Description

@likeajohny

Do I misunderstand the @psalm-assert-if-true Assertion?

The Uuid::isValid method has a psalm assertion @psalm-assert-if-true non-empty-string $uuid set.
This assertion seems to lead Psalm to think that only non-empty-strings can be given to this method and any false validation means that the given string is empty.
At least that's what I'm guessing after receiving the following error
All possible types for this argument were invalidated - This may be dead code
in a project of mine.

Example code

Here's a simplified version of the problematic code. I've just mocked a Uuid::isValid implementation for demo purposes.

https://psalm.dev/r/764e8e9309

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions