diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 90028e8f3b9..b32ad3b3d46 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1030,14 +1030,12 @@ 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 TNonEmptyString - && $type->value !== '' + && ($combination->value_types['string'] instanceof TNonFalsyString + ? $type->value + : $type->value !== '' + ) ) { // do nothing } else { 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"', + ], + ], ]; }