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

prevent Psalm from considering throwing methods as unused just because they're immutable #6972

Merged
merged 2 commits into from Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -112,6 +112,7 @@ public static function analyze(
&& !$method_storage->assertions
&& !$method_storage->if_true_assertions
&& !$method_storage->if_false_assertions
&& !$method_storage->throws
) {
if (IssueBuffer::accepts(
new \Psalm\Issue\UnusedMethodCall(
Expand Down
21 changes: 21 additions & 0 deletions tests/UnusedCodeTest.php
Expand Up @@ -1162,6 +1162,27 @@ private function assert(?string $val): void {
$a = new A();
echo $a->getVal(null);',
],
'NotUnusedWhenThrows' => [
'<?php
declare(strict_types=1);
/** @psalm-immutable */
final class UserList
{
/**
* @throws InvalidArgumentException
*/
public function validate(): void
{
// Some validation happens here
throw new \InvalidArgumentException();
}
}
$a = new UserList();
$a->validate();
',
],
'__halt_compiler_no_usage_check' => [
'<?php
exit(0);
Expand Down