-
Notifications
You must be signed in to change notification settings - Fork 651
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
InvalidReturnType incorrect error #6386
Labels
Comments
I found these snippets: https://psalm.dev/r/d75a4c2020<?php
class Test {
private int $retryAttempts = 10;
private function getResult(): string
{
// return tring or throw exception whatever
throw new Exception();
}
private function getResultWithRetry(): string
{
$attempt = 1;
while (true) {
try {
return $this->getResult();
} catch (Throwable $exception) {
if ($attempt >= $this->retryAttempts) {
throw $exception;
}
$attempt++;
continue;
}
}
}
}
|
As a workaround, you can throw exception after the |
I found these snippets: https://psalm.dev/r/1e77336875<?php
class Test {
private int $retryAttempts = 10;
private function getResult(): string
{
// return tring or throw exception whatever
throw new Exception();
}
private function getResultWithRetry(): string
{
$attempt = 1;
while (true) {
try {
return $this->getResult();
} catch (Throwable $exception) {
if ($attempt >= $this->retryAttempts) {
throw $exception;
}
$attempt++;
continue;
}
}
throw new RuntimeException('should never happen');
}
}
|
Sorry, but it is incorrect dead code. IDE and phpstan will sound the alarm. |
I found these snippets: https://psalm.dev/r/1e77336875<?php
class Test {
private int $retryAttempts = 10;
private function getResult(): string
{
// return tring or throw exception whatever
throw new Exception();
}
private function getResultWithRetry(): string
{
$attempt = 1;
while (true) {
try {
return $this->getResult();
} catch (Throwable $exception) {
if ($attempt >= $this->retryAttempts) {
throw $exception;
}
$attempt++;
continue;
}
}
throw new RuntimeException('should never happen');
}
}
|
simplified: |
I found these snippets: https://psalm.dev/r/bd185e9e6a<?php
function getResultWithRetry(): string
{
while (true) {
return '';
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example
https://psalm.dev/r/d75a4c2020
Code above throws exception or returns string.
The text was updated successfully, but these errors were encountered: