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

Inaccurate error with different types in PHPDoc and typehint #6128

Closed
i582 opened this issue Jul 17, 2021 · 1 comment · Fixed by #6187
Closed

Inaccurate error with different types in PHPDoc and typehint #6128

i582 opened this issue Jul 17, 2021 · 1 comment · Fixed by #6187
Labels

Comments

@i582
Copy link

i582 commented Jul 17, 2021

Link to the playground: https://psalm.dev/r/616eb6fd60

image

It seems that there should not be a null|string type here, since the type in PHPDoc @return is just string.
This also happens if you set the same types for the parameters of a function or properties of a class.

P.S. Thanks for the great tool! Psalm gives me a lot of inspiration.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/616eb6fd60
<?php

/**
 * @return string
 */
function getInt(int $i): ?int {
    if ($i) {
      return null;   
    }
    return 0;
}
Psalm output (using commit 2127da3):

ERROR: MismatchingDocblockReturnType - 4:12 - Docblock has incorrect return type 'null|string', should be 'int|null'

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

Successfully merging a pull request may close this issue.

2 participants