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

Not all code paths end in a return statement #4327

Closed
vudaltsov opened this issue Oct 14, 2020 · 1 comment
Closed

Not all code paths end in a return statement #4327

vudaltsov opened this issue Oct 14, 2020 · 1 comment
Labels

Comments

@vudaltsov
Copy link
Contributor

Since psalm 3.17 a function with a continue statement and a switch with returns is reported as invalid.

https://psalm.dev/r/b521fae60c

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/b521fae60c
<?php

function a(): int
{
    switch (random_int(1, 10)) {
        case 1: 
            return 1;
        default:
            return 2;
    }
}


function b(): int
{
    foreach([1,2] as $i) {
    	continue;
    }
    
    switch (random_int(1, 10)) {
        case 1: 
            return 1;
        default:
            return 2;
    }
}
Psalm output (using commit 724b25b):

ERROR: InvalidReturnType - 14:15 - Not all code paths of b end in a return statement, return type int expected

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

No branches or pull requests

2 participants