From 5fccb339380a9c78492fb9e8c363dee71f4e0a86 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:12:03 +0100 Subject: [PATCH] dont combine empty string with numeric-string Fix https://github.com/vimeo/psalm/issues/6646 --- src/Psalm/Internal/Type/TypeCombiner.php | 3 +++ tests/TypeCombinationTest.php | 32 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 773e3f71a..e21d41b05 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1080,6 +1080,9 @@ final class TypeCombiner if ($has_only_numeric_strings) { $combination->value_types['string'] = $type; + } elseif (count($combination->strings) === 1 && !$has_only_non_empty_strings) { + $combination->value_types['string'] = $type; + return; } elseif ($has_only_non_empty_strings) { $combination->value_types['string'] = new TNonEmptyString(); } else { diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index c3371ef2a..b891e84dc 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -88,6 +88,38 @@ class TypeCombinationTest extends TestCase } ', ], + 'emptyStringNumericStringDontCombine' => [ + 'code' => ' [ + 'code' => '