-
Notifications
You must be signed in to change notification settings - Fork 654
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
False positive InvalidReturnType for method that always throws #9604
Comments
I found these snippets: https://psalm.dev/r/b8245d5f63<?php
class Logger
{
public static function logCall(string $method): void
{
}
}
abstract class MyAbstractClass
{
/**
* @return string
*/
public function doSomething()
{
Logger::logCall(__METHOD__);
throw new Exception('Not supported.');
}
}
|
ping @kkmuffme I believe this is linked to your changes around never |
Similar to/Inverse of #10377 The underlying problem is, that for @return we use explicit I suggest to just suppress the error, as this cannot be fixed. |
I found these snippets: https://psalm.dev/r/70d79e581f<?php
class Logger
{
public static function logCall(string $method): void
{
}
}
abstract class MyAbstractClass
{
/**
* @return string
*/
public function doSomething()
{
throw new Exception('Not supported.');
}
}
|
Thank you for your answer. That's of course not very satisfying, but I think I can live with ignoring this error. |
Given the following code:
https://psalm.dev/r/b8245d5f63
Psalm reports:
I would argue that the return type is still correct, it's just that the return type inferred by Psalm is more specific. The problem here is that this method is overridden by child classes and those implementations actually return a string. If I would document
@return never
here, the child implementation would illegally widen the return type fromnever
tostring
.Note that the error goes away if I…
string
.Logger::logCall(__METHOD__);
line from the method.Both should be pretty much irrelevant for the issue. 🤔
The text was updated successfully, but these errors were encountered: