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

Nested if constraints bleeding to wider scope #10267

Open
robchett opened this issue Oct 8, 2023 · 1 comment
Open

Nested if constraints bleeding to wider scope #10267

robchett opened this issue Oct 8, 2023 · 1 comment

Comments

@robchett
Copy link
Contributor

robchett commented Oct 8, 2023

Merging #10209 into master has surfaced what I believe is a bug with if constraints

Digging deeper it looks like the removal of TList was the issue, it sufficiently changed the if statement to surface what I assume is a bug - a minimal repo is this is https://psalm.dev/r/577ae8535e

Would baselining these warnings or re-annotating $left_type_part/$right_type_part to Atomic be OK until that issue can be resolved?

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/577ae8535e
<?php

/**
 * @param 1|2|3 $a
 * @param 1|2|3 $b
 */
function test(int $a, int $b): string {
    if ($a == 1 || $a == 2 || $b == 1 || $b == 2) {
        if ($b == 3 || $a == 3) {
            return 'false1';
        }
    }

    if ($a == 3) {
        return 'true';
    }
    
    return 'false2';
}

print_r(test(3, 3));
Psalm output (using commit 1b12255):

ERROR: DocblockTypeContradiction - 14:9 - 3 does not contain 1|2

ERROR: DocblockTypeContradiction - 14:9 - Docblock-defined type 1|2 for $a is never =int(3)

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