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

Literal Strings else/elseif incorrect type #10487

Open
kkmuffme opened this issue Dec 13, 2023 · 1 comment
Open

Literal Strings else/elseif incorrect type #10487

kkmuffme opened this issue Dec 13, 2023 · 1 comment

Comments

@kkmuffme
Copy link
Contributor

https://psalm.dev/r/9ac5444f9d

There currently is a test for this https://github.com/vimeo/psalm/blob/5.x/tests/TypeReconciliation/ValueTest.php#L275 but as shown in the snippet above, this test is useless, because the types are wrong in the if and the else

Copy link

I found these snippets:

https://psalm.dev/r/9ac5444f9d
<?php

$a = rand(0, 1) ? "a" : "b";
$b = rand(0, 1) ? "a" : "b";

$s = rand(0, 1) ? $a : $b;
if (rand(0, 1)) $s = "c";

if ($s === $a) {
    /** @psalm-trace $s */;
    /** @psalm-trace $a */;
} elseif ($s === $b) {
    /** @psalm-trace $s */;
    /** @psalm-trace $b */;
}
Psalm output (using commit a75d26a):

INFO: Trace - 10:27 - $s: 'a'

INFO: Trace - 11:27 - $a: 'a'|'b'

INFO: Trace - 13:27 - $s: 'b'

INFO: Trace - 14:27 - $b: 'b'

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