Skip to content

Commit

Permalink
Merge pull request #10039 from nicelocal/non_falsy_string_literal
Browse files Browse the repository at this point in the history
Fix combination of non-falsy-string and falsy literal
  • Loading branch information
orklah committed Jul 29, 2023
2 parents 7e4a6f5 + 63347e7 commit 80ddbd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Psalm/Internal/Type/TypeCombiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1033,14 +1033,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 {
Expand Down
7 changes: 7 additions & 0 deletions tests/TypeCombinationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,13 @@ public function providerTestValidTypeCombination(): array
'non-empty-literal-string',
],
],
'nonFalsyStringAndFalsyLiteral' => [
'string',
[
'non-falsy-string',
'"0"',
],
],
];
}

Expand Down

0 comments on commit 80ddbd3

Please sign in to comment.