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

Incorrect type for RuntimeException::getCode() #7672

Closed
AndrolGenhald opened this issue Feb 14, 2022 · 6 comments · Fixed by #7673
Closed

Incorrect type for RuntimeException::getCode() #7672

AndrolGenhald opened this issue Feb 14, 2022 · 6 comments · Fixed by #7673
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm Help wanted

Comments

@AndrolGenhald
Copy link
Collaborator

https://psalm.dev/r/512ac9662c https://3v4l.org/RBCW0

@VincentLanglet re #7390

I suggest copy/pasting

&& $premixin_method_id->fq_class_name !== Exception::class
and doing a RuntimeException::class check as well.

Also, PDOException should return int|string (or maybe 0|string but I'm not sure): https://3v4l.org/9vu2u

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/512ac9662c
<?php

try {
    throw new PDOException();
} catch (RuntimeException $e) {
    $code = $e->getCode();
    /** @psalm-trace $code */;
}
Psalm output (using commit 5aa06ae):

INFO: Trace - 7:30 - $code: int

INFO: UnusedVariable - 6:5 - $code is never referenced or the value is not used

@VincentLanglet
Copy link
Contributor

I followed PHPStan on this https://phpstan.org/r/42089d28-dbaa-4b67-ac00-154372ce55a8
But indeed, it need to be fixed.

@orklah
Copy link
Collaborator

orklah commented Feb 14, 2022

PDOException is a child of RuntimeException? :o

What a mess :( ...

@orklah orklah added bug easy problems Issues that can be fixed without background knowledge of Psalm Help wanted labels Feb 14, 2022
@VincentLanglet
Copy link
Contributor

I just opened an issue phpstan/phpstan#6651 and a PR phpstan/phpstan-src#1018 on PHPStan. I'll hope it will be reviewed quickly to be sure phpstan is going in the same direction.

Do you want to make the fix on psalm @AndrolGenhald or should I ?

@AndrolGenhald
Copy link
Collaborator Author

You can go ahead, I'm in the middle of rewriting TryAnalyzer.

@VincentLanglet
Copy link
Contributor

I made #7673. But I would recommend to wait for a response from the phpstan-side in order to copy the behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm Help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants