diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index c0e4e9e5c..544aacee2 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -632,6 +632,13 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer } foreach ($storage->throws as $expected_exception => $_) { + if (($expected_exception === 'self' + || $expected_exception === 'static') + && $context->self + ) { + $expected_exception = $context->self; + } + if (isset($storage->throw_locations[$expected_exception])) { if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName( $statements_analyzer, diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 7fed70bb3..cca634f6e 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -1071,6 +1071,18 @@ class AnnotationTest extends TestCase $data = json_decode("{}", false); consume($data->value ?? "");' ], + 'throwSelf' => [ + '