From 2fff4eb5c1fa83029f88587b0199e5d431dc2906 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 22 Nov 2020 00:26:14 -0500 Subject: [PATCH] Fix #4653 - prevent crash with recursive type in root namespace --- src/Psalm/Type/Atomic.php | 4 ++-- tests/TypeAnnotationTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index b09620fdc..35d3f8764 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -90,7 +90,7 @@ abstract class Atomic implements TypeNode /** * @param array{int,int}|null $php_version * @param array> $template_type_map - * @param array $type_aliases + * @param array $type_aliases */ public static function create( string $value, @@ -277,7 +277,7 @@ abstract class Atomic implements TypeNode return new TTypeAlias($type_alias->declaring_fq_classlike_name, $type_alias->alias_name); } - throw new \UnexpectedValueException('This should never happen'); + throw new \Psalm\Exception\TypeParseTreeException('Invalid type alias ' . $value . ' provided'); } return new TNamedObject($value); diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 3ae85cd90..aa9aedac0 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -521,6 +521,18 @@ class TypeAnnotationTest extends TestCase }', 'error_message' => 'PossiblyUndefinedArrayOffset', ], + 'noCrashWithSelfReferencingType' => [ + ' 'InvalidDocblock', + ], ]; } }