Skip to content

Commit

Permalink
Merge pull request #10930 from VincentLanglet/literalStringUnion
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed May 5, 2024
2 parents 08ea062 + 4b10905 commit 10956df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Psalm/Internal/Type/TypeCombiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1227,9 +1227,16 @@ private static function scrapeStringProperties(
) {
$combination->value_types['string'] = new TNonEmptyString();
} elseif (get_class($type) === TNonEmptyNonspecificLiteralString::class
&& $combination->value_types['string'] instanceof TNonEmptyString
&& (
$combination->value_types['string'] instanceof TNonEmptyString
|| $combination->value_types['string'] instanceof TNonspecificLiteralString
)
) {
// do nothing
} elseif (get_class($type) === TNonspecificLiteralString::class
&& get_class($combination->value_types['string']) === TNonEmptyNonspecificLiteralString::class
) {
$combination->value_types['string'] = $type;
} else {
$combination->value_types['string'] = new TString();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/TypeCombinationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,20 @@ public function providerTestValidTypeCombination(): array
'class-string<IFoo & IBar>',
],
],
'unionNonEmptyLiteralStringAndLiteralString' => [
'literal-string',
[
'non-empty-literal-string',
'literal-string',
],
],
'unionLiteralStringAndNonEmptyLiteralString' => [
'literal-string',
[
'literal-string',
'non-empty-literal-string',
],
],
];
}

Expand Down

0 comments on commit 10956df

Please sign in to comment.