From dfbc9dd177d00e74334748f539409abf85bdee11 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 24 Jul 2023 09:07:46 +0200 Subject: [PATCH 1/2] Fix combination of non-falsy-string and falsy literal --- src/Psalm/Internal/Type/TypeCombiner.php | 5 ----- tests/TypeCombinationTest.php | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index d091c239961..5577a10ac29 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1038,11 +1038,6 @@ private static function scrapeStringProperties( && $type->value ) { // do nothing - } elseif (isset($combination->value_types['string']) - && $combination->value_types['string'] instanceof TNonEmptyString - && $type->value !== '' - ) { - // do nothing } else { $combination->value_types['string'] = new TString(); } diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index 5a74bc01266..c3371ef2a6b 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -860,6 +860,13 @@ public function providerTestValidTypeCombination(): array 'non-empty-literal-string', ], ], + 'nonFalsyStringAndFalsyLiteral' => [ + 'string', + [ + 'non-falsy-string', + '"0"', + ], + ], ]; } From a86aa9a30bf2db2091c097ad13eb31a4538be2fb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 24 Jul 2023 09:25:57 +0200 Subject: [PATCH 2/2] Fix --- src/Psalm/Internal/Type/TypeCombiner.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 5577a10ac29..ee1dd03cd27 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1034,8 +1034,11 @@ private static function scrapeStringProperties( ) { // do nothing } elseif (isset($combination->value_types['string']) - && $combination->value_types['string'] instanceof TNonFalsyString - && $type->value + && $combination->value_types['string'] instanceof TNonEmptyString + && ($combination->value_types['string'] instanceof TNonFalsyString + ? $type->value + : $type->value !== '' + ) ) { // do nothing } else {