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 3f6a7de
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Psalm/Internal/Type/TypeCombiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,19 +1051,25 @@ private static function scrapeStringProperties(
if (!isset($combination->value_types['string'])) {
if ($combination->strings) {
if ($type instanceof TNumericString) {
$has_non_numeric_string = false;
$has_only_numeric_strings = true;
$has_only_non_empty_strings = true;

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

if ($string_type->value === '') {
$has_only_non_empty_strings = false;
}
}

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

0 comments on commit 3f6a7de

Please sign in to comment.