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

Confusion with conditional on false #3737

Closed
andyg0808 opened this issue Jul 3, 2020 · 1 comment
Closed

Confusion with conditional on false #3737

andyg0808 opened this issue Jul 3, 2020 · 1 comment
Labels

Comments

@andyg0808
Copy link

I think both examples here should pass, but only the one with null does:
https://psalm.dev/r/ad857f2e4b

@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @template T as int|false
 * @param T $value
 * @return int
 */
function falseDoesntWork($value) {
    if ($value === false) {
       return -1;
    }
    return $value;
}

/**
 * @template T as int|null
 * @param T $value
 * @return int
 */
function butNullDoes($value) {
    if ($value === null) {
       return -1;
    }
    return $value;
}
Psalm output (using commit ba63ccb):

ERROR: DocblockTypeContradiction - 9:9 - T does not contain false

ERROR: FalsableReturnStatement - 12:12 - The declared return type 'int' for falseDoesntWork does not allow false, but the function returns 'T'

ERROR: InvalidFalsableReturnType - 6:12 - The declared return type 'int' for falseDoesntWork does not allow false, but 'T|int' contains false

@weirdan weirdan added the bug label Jul 3, 2020
@muglug muglug closed this as completed in 6419788 Jul 3, 2020
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