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

Trouble with switch case in try catch block #11016

Open
bless-rng opened this issue Jun 17, 2024 · 1 comment
Open

Trouble with switch case in try catch block #11016

bless-rng opened this issue Jun 17, 2024 · 1 comment

Comments

@bless-rng
Copy link

bless-rng commented Jun 17, 2024

As you can see switch block has all cases. Try block also has all cases for correct resolve result. If switch case replace with if else block this case also is correct.
Variable $x is not possible to be undefined.

https://psalm.dev/r/14034f3334

Copy link

psalm-github-bot bot commented Jun 17, 2024

I found these snippets:

https://psalm.dev/r/14034f3334
<?php

function getX(string $s): int {
	try {
        switch ($s) {
            case 'S':
                $x = 1;
                break;
            case 'F':
                $x = 2;
                break;
            default: 
                $x = 3;
                break;
        }
    } catch (Throwable $e) {
        $x = 0;
    }
    return $x;
}
Psalm output (using commit 16b24bd):

INFO: PossiblyUndefinedVariable - 19:12 - Possibly undefined variable $x defined in try block

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