mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Don't crash on unknown exceptions in @throws
docblock
Fixes vimeo/psalm#9248
This commit is contained in:
parent
4eacb2f234
commit
250d4d593e
@ -710,7 +710,10 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
||||
|
||||
foreach ($storage->throws as $expected_exception => $_) {
|
||||
if ($expected_exception === $possibly_thrown_exception
|
||||
|| $codebase->classExtendsOrImplements($possibly_thrown_exception, $expected_exception)
|
||||
|| (
|
||||
$codebase->classOrInterfaceExists($possibly_thrown_exception)
|
||||
&& $codebase->classExtendsOrImplements($possibly_thrown_exception, $expected_exception)
|
||||
)
|
||||
) {
|
||||
$is_expected = true;
|
||||
break;
|
||||
|
@ -634,4 +634,29 @@ class ThrowsAnnotationTest extends TestCase
|
||||
|
||||
$this->analyzeFile('somefile.php', $context);
|
||||
}
|
||||
|
||||
public function testUnknownExceptionInThrowsOfACalledMethod(): void
|
||||
{
|
||||
$this->expectExceptionMessage('MissingThrowsDocblock');
|
||||
$this->expectException(CodeException::class);
|
||||
Config::getInstance()->check_for_throws_docblock = true;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
final class Monkey {
|
||||
/** @throws InvalidArgumentException */
|
||||
public function spendsItsDay(): void {
|
||||
$this->havingFun();
|
||||
}
|
||||
/** @throws \Monkey\Shit */
|
||||
private function havingFun(): void {}
|
||||
}
|
||||
',
|
||||
);
|
||||
|
||||
$context = new Context();
|
||||
|
||||
$this->analyzeFile('somefile.php', $context);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user