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

Psalter wants to add "@result never" in void methods #8912

Closed
UlrichBoehm opened this issue Dec 17, 2022 · 5 comments · Fixed by #9026
Closed

Psalter wants to add "@result never" in void methods #8912

UlrichBoehm opened this issue Dec 17, 2022 · 5 comments · Fixed by #9026

Comments

@UlrichBoehm
Copy link

Running the following code with psalter (dry-run, all issues) leads to the suggestion to add a doc block with "(at)return never" which is wrong.

function checkForFoo(string $test): void
{
    if (str_contains($test, 'foo')) {
        throw new \Exception('No Foo here!');
    }
}

FYI @kkmuffme

@psalm-github-bot
Copy link

Hey @UlrichBoehm, can you reproduce the issue on https://psalm.dev ?

@UlrichBoehm
Copy link
Author

It's reproducible as soon as you enable the setting "Force return types to be as tight as possible".
https://psalm.dev/r/40196637cc

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/40196637cc
<?php

function checkForFoo(string $test): void
{
    if (str_contains($test, 'foo')) {
        throw new \Exception('No Foo here!');
    }
}
Psalm output (using commit ef02ded):

INFO: LessSpecificReturnType - 3:37 - The inferred return type 'never' for checkForFoo is more specific than the declared return type 'void'

@kkmuffme
Copy link
Contributor

Duplicate of #8862
This is not a bug with the "never" check, but a bug in general, e.g.
https://psalm.dev/r/b0e397c14e
https://psalm.dev/r/6ffb302b9e

Please create a PR to fix the implicit returns

@psalm-github-bot
Copy link

I found these snippets:

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

function foo(): void
{
    if (random_int(0, 1) === 1) {
        return false;
    }
}
Psalm output (using commit ef02ded):

ERROR: InvalidReturnStatement - 6:16 - No return values are expected for foo

INFO: LessSpecificReturnType - 3:17 - The inferred return type 'false' for foo is more specific than the declared return type 'void'

ERROR: InvalidFalsableReturnType - 3:17 - The declared return type 'void' for foo does not allow false, but 'false' contains false
https://psalm.dev/r/6ffb302b9e
<?php

function foo(): void
{
    if (random_int(0, 1) === 1) {
        return 10;
    }
}
Psalm output (using commit ef02ded):

ERROR: InvalidReturnStatement - 6:16 - No return values are expected for foo

ERROR: InvalidReturnType - 3:17 - The declared return type 'void' for foo is incorrect, got '10'

kkmuffme added a commit to kkmuffme/psalm that referenced this issue Dec 29, 2022
* fix implicit void return type errors https://psalm.dev/r/b0e397c14e
* fix void + never = null return type error https://psalm.dev/r/6f227ae9b9
* fixes vimeo#8912 and vimeo#8862
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Dec 29, 2022
* fix implicit void return type errors https://psalm.dev/r/b0e397c14e
* fix void + never = null return type error https://psalm.dev/r/6f227ae9b9
* fixes vimeo#8912 and vimeo#8862
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Dec 29, 2022
* fix implicit void return type errors https://psalm.dev/r/b0e397c14e
* fix void + never = null return type error https://psalm.dev/r/6f227ae9b9
* fixes vimeo#8912 and vimeo#8862
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 5, 2023
* fix implicit void return type errors https://psalm.dev/r/b0e397c14e
* fix void + never = null return type error https://psalm.dev/r/6f227ae9b9
* fixes vimeo#8912 and vimeo#8862
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants