Skip to content

Commit

Permalink
Merge pull request #7105 from AndrolGenhald/bugfix/7095
Browse files Browse the repository at this point in the history
Fix non-empty-literal-string to behave as subtype of non-empty-string (fixes #7095).
  • Loading branch information
orklah committed Dec 8, 2021
2 parents 8bd525a + a89e8ec commit b65e37c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Psalm/Internal/Type/TypeCombiner.php
Expand Up @@ -38,6 +38,7 @@
use Psalm\Type\Atomic\TNonEmptyList;
use Psalm\Type\Atomic\TNonEmptyLowercaseString;
use Psalm\Type\Atomic\TNonEmptyMixed;
use Psalm\Type\Atomic\TNonEmptyNonspecificLiteralString;
use Psalm\Type\Atomic\TNonEmptyString;
use Psalm\Type\Atomic\TNonFalsyString;
use Psalm\Type\Atomic\TNonspecificLiteralInt;
Expand Down Expand Up @@ -1131,6 +1132,15 @@ private static function scrapeStringProperties(
&& get_class($type) === TNonEmptyLowercaseString::class
) {
//no-change
} elseif (get_class($combination->value_types['string'])
=== TNonEmptyNonspecificLiteralString::class
&& $type instanceof TNonEmptyString
) {
$combination->value_types['string'] = new TNonEmptyString();
} elseif (get_class($type) === TNonEmptyNonspecificLiteralString::class
&& $combination->value_types['string'] instanceof TNonEmptyString
) {
// do nothing
} else {
$combination->value_types['string'] = new TString();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/TypeCombinationTest.php
Expand Up @@ -801,6 +801,20 @@ public function providerTestValidTypeCombination(): array
'positive-int',
]
],
'combineNonEmptyStringAndNonEmptyNonSpecificLiteralString' => [
'non-empty-string',
[
'non-empty-literal-string',
'non-empty-string',
],
],
'combineNonEmptyNonSpecificLiteralStringAndNonEmptyString' => [
'non-empty-string',
[
'non-empty-string',
'non-empty-literal-string',
],
],
];
}

Expand Down

0 comments on commit b65e37c

Please sign in to comment.