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' => '