From d5f4c24ee0796357f410eed54697f9e814c553d1 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 1 Dec 2019 23:03:09 -0500 Subject: [PATCH] Fix combining class string types with explicit ones --- src/Psalm/Internal/Type/TypeCombination.php | 9 +++++++++ tests/TypeCombinationTest.php | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/Psalm/Internal/Type/TypeCombination.php b/src/Psalm/Internal/Type/TypeCombination.php index 74865a4b5..28e4f8d83 100644 --- a/src/Psalm/Internal/Type/TypeCombination.php +++ b/src/Psalm/Internal/Type/TypeCombination.php @@ -475,6 +475,15 @@ class TypeCombination } if ($combination->class_string_types) { + if ($combination->strings) { + foreach ($combination->strings as $k => $string) { + if ($string instanceof TLiteralClassString) { + $combination->class_string_types[$string->value] = new TNamedObject($string->value); + unset($combination->strings[$k]); + } + } + } + if (!isset($combination->value_types['string'])) { $object_type = self::combineTypes( array_values($combination->class_string_types), diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index cf9b4cb05..e30082d83 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -473,6 +473,13 @@ class TypeCombinationTest extends TestCase 'class-string', ], ], + 'combineClassStringsWithLiteral' => [ + 'class-string', + [ + 'class-string', + 'Exception::class', + ], + ], ]; }