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

Code path false positive with while(true) and no breaks #7817

Closed
Jean85 opened this issue Mar 25, 2022 · 3 comments
Closed

Code path false positive with while(true) and no breaks #7817

Jean85 opened this issue Mar 25, 2022 · 3 comments

Comments

@Jean85
Copy link
Contributor

Jean85 commented Mar 25, 2022

https://psalm.dev/r/06329b768b

<?php

function foo(bool $throw): bool
{
    do {
        if ($throw) {
            throw new \Exception();
        }

        return true;
    } while (true);
}

Reported false positive:

ERROR: [InvalidReturnType](https://psalm.dev/011) - 3:28 - Not all code paths of foo end in a return statement, return type bool expected
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/06329b768b
<?php

function foo(bool $throw): bool
{
    do {
        if ($throw) {
            throw new \Exception();
        }

        return true;
    } while (true);
}
Psalm output (using commit 5baf85e):

ERROR: InvalidReturnType - 3:28 - Not all code paths of foo end in a return statement, return type bool expected

@theodorejb
Copy link
Contributor

I think this is the same issue as #7842.

@theodorejb
Copy link
Contributor

This was also fixed by #8929.

@orklah orklah closed this as completed Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants