From 4ac18720aab9dda3c3fc3d5a2d55d8ce2fdf5150 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:41:29 +0100 Subject: [PATCH] Revert https://github.com/vimeo/psalm/pull/10039 and fix type and test --- src/Psalm/Internal/Type/TypeCombiner.php | 15 +++++++++++---- tests/TypeCombinationTest.php | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 0a084e8a62f..099ae82c7fc 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1047,12 +1047,19 @@ private static function scrapeStringProperties( && strtolower($type->value) === $type->value ) { // do nothing + } elseif (isset($combination->value_types['string']) + && $combination->value_types['string'] instanceof TNonFalsyString + && $type->value + ) { + // do nothing + } elseif (isset($combination->value_types['string']) + && $combination->value_types['string'] instanceof TNonFalsyString + && $type->value === '0' + ) { + $combination->value_types['string'] = new TNonEmptyString(); } elseif (isset($combination->value_types['string']) && $combination->value_types['string'] instanceof TNonEmptyString - && ($combination->value_types['string'] instanceof TNonFalsyString - ? $type->value - : $type->value !== '' - ) + && $type->value !== '' ) { // do nothing } else { diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index ba3ded5e83d..841fbd67e36 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -934,7 +934,7 @@ public function providerTestValidTypeCombination(): array ], ], 'nonFalsyStringAndFalsyLiteral' => [ - 'string', + 'non-empty-string', [ 'non-falsy-string', '"0"',