Skip to content

Commit

Permalink
Allow suppressing thrown interfaces and their descendants (#5178)
Browse files Browse the repository at this point in the history
Fixes #5177
  • Loading branch information
weirdan committed Feb 8, 2021
1 parent 3bf7a73 commit e3d73a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Expand Up @@ -949,6 +949,7 @@ public function getUncaughtThrows(Context $context): array
try {
if ($expected_exception === strtolower($possibly_thrown_exception)
|| $this->codebase->classExtends($possibly_thrown_exception, $expected_exception)
|| $this->codebase->interfaceExtends($possibly_thrown_exception, $expected_exception)
) {
$is_expected = true;
break;
Expand Down
35 changes: 29 additions & 6 deletions tests/Config/ConfigTest.php
Expand Up @@ -1142,6 +1142,7 @@ public function testIgnoreExceptions(): void
<class name="Exc2" onlyGlobalScope="true" />
<classAndDescendants name="Exc3" />
<classAndDescendants name="Exc4" onlyGlobalScope="true" />
<classAndDescendants name="Exc5" />
</ignoreExceptions>
</psalm>'
)
Expand All @@ -1153,18 +1154,40 @@ public function testIgnoreExceptions(): void
$file_path,
'<?php
class Exc1 extends Exception {}
/** @throws Exc1 */
function throwsExc1(): void {}
class Exc2 extends Exception {}
/** @throws Exc2 */
function throwsExc2(): void {}
class Exc3 extends Exception {}
/** @throws Exc3 */
function throwsExc3(): void {}
class Exc4 extends Exception {}
/** @throws Exc4 */
function throwsExc4(): void {}
interface Exc5 {}
interface Exc6 extends Exc5 {}
/**
* @psalm-suppress InvalidThrow
* @throws Exc6
*/
function throwsExc6() : void {}
throw new Exc1();
throw new Exc2();
throw new Exc3();
throw new Exc4();
throwsExc1();
throwsExc2();
throwsExc3();
throwsExc4();
throwsExc6();
function example() : void {
throw new Exc1();
throw new Exc3();
throwsExc6();
throwsExc1();
throwsExc3();
throwsExc6();
}'
);

Expand Down

0 comments on commit e3d73a3

Please sign in to comment.