Skip to content
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

RedundantCondition on nullable enum is a false positive #11171

Open
Jean85 opened this issue Nov 27, 2024 · 1 comment
Open

RedundantCondition on nullable enum is a false positive #11171

Jean85 opened this issue Nov 27, 2024 · 1 comment

Comments

@Jean85
Copy link
Contributor

Jean85 commented Nov 27, 2024

If I have a nullable backed enum, and I try to concatenate it with a null coalesce, I get two errors, but those are false positives.
It works if I suppress it with a nullsafe accessor, but that's redundant (see https://3v4l.org/ZZpui)

https://psalm.dev/r/6304b00b6f

Copy link

I found these snippets:

https://psalm.dev/r/6304b00b6f
<?php

enum Something: string {
    case A = 'A';
    case B = 'B';
}

function test(?Something $foo): void {
    echo $foo?->value ?? 'nullsafe'; // nullsafe accessor is not needed!
    echo $foo->value ?? 'nullsafe'; // false positive
}
Psalm output (using commit 986ef8d):

ERROR: RedundantCondition - 10:10 - Type 'A'|'B' for $foo->value is always isset

ERROR: TypeDoesNotContainType - 10:25 - Cannot resolve types for $foo->value with type string and !isset assertion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant