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

linter: add finally return check for unreachable checker #973

Merged
merged 10 commits into from
Apr 27, 2021

Conversation

i582
Copy link
Contributor

@i582 i582 commented Apr 14, 2021

Report the use of return in finally when
there are other return, throw in the try-catch.

The problem is they will be unreachable.

For example:

function f(): int {
  try {
    throwException();
  } catch (Exception $_) {
    return 2; // unreachable
  } finally {
    return 1;
  }
}

f(); // always return 1

Report the use of die in catch when
there are finally block.

The problem is finally will be unreachable.

function f(): int {
    try {
        throwException();
    } catch (RuntimeException $_) {
        return 2;
    } catch (Exception $_) {
        die();
    } finally { // block finally is unreachable (because 2 catch block contains a exit/die)
        return 1;
    }
}

#332

i582 added 3 commits April 14, 2021 13:31
Report the use of return in finally when
there are other return, throw, die, etc.
in the try-catch.
@i582 i582 changed the title linter: add finallyReturn checker linter: add finally return check for unreachable checker Apr 14, 2021
src/linter/block.go Outdated Show resolved Hide resolved
i582 added 2 commits April 26, 2021 20:48
src/linter/block.go Outdated Show resolved Hide resolved
@quasilyte quasilyte merged commit b391fed into VKCOM:master Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants