Skip to content

Commit

Permalink
bugfix: preserve non-empty-string type when combining literal-string …
Browse files Browse the repository at this point in the history
…with numeric-string types

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
  • Loading branch information
boesing committed Apr 10, 2023
1 parent 10e7299 commit e77a3ef
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Psalm/Internal/Type/TypeCombiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1052,15 +1052,22 @@ private static function scrapeStringProperties(
if ($combination->strings) {
if ($type instanceof TNumericString) {
$has_non_numeric_string = false;
$has_only_non_empty_strings = true;

foreach ($combination->strings as $string_type) {
if (!is_numeric($string_type->value)) {
$has_non_numeric_string = true;
break;
}

if (!$string_type instanceof TNonEmptyString
&& !($string_type instanceof TLiteralString && $string_type->value !== '')) {
$has_only_non_empty_strings = false;
}
}

if ($has_non_numeric_string) {
if ($has_only_non_empty_strings) {
$combination->value_types['string'] = new TNonEmptyString();
} elseif ($has_non_numeric_string) {
$combination->value_types['string'] = new TString();
} else {
$combination->value_types['string'] = $type;
Expand Down

0 comments on commit e77a3ef

Please sign in to comment.