mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
Fix #5017 - handle combining literal and non-empty strings
This commit is contained in:
parent
0107afb2fb
commit
75d1f79a3d
@ -931,6 +931,11 @@ class TypeCombiner
|
||||
&& \strtolower($type->value) === $type->value
|
||||
) {
|
||||
// do nothing
|
||||
} elseif (isset($combination->value_types['string'])
|
||||
&& $combination->value_types['string'] instanceof Type\Atomic\TNonEmptyString
|
||||
&& $type->value
|
||||
) {
|
||||
// do nothing
|
||||
} else {
|
||||
$combination->value_types['string'] = new TString();
|
||||
}
|
||||
@ -974,6 +979,23 @@ class TypeCombiner
|
||||
$combination->value_types['string'] = $type;
|
||||
}
|
||||
|
||||
$combination->strings = null;
|
||||
} elseif ($type instanceof Type\Atomic\TNonEmptyString) {
|
||||
$has_empty_string = false;
|
||||
|
||||
foreach ($combination->strings as $string_type) {
|
||||
if (!$string_type->value) {
|
||||
$has_empty_string = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($has_empty_string) {
|
||||
$combination->value_types['string'] = new TString();
|
||||
} else {
|
||||
$combination->value_types['string'] = $type;
|
||||
}
|
||||
|
||||
$combination->strings = null;
|
||||
} else {
|
||||
$has_non_literal_class_string = false;
|
||||
|
@ -644,6 +644,20 @@ class TypeCombinationTest extends TestCase
|
||||
'array{0?:int}',
|
||||
]
|
||||
],
|
||||
'combinNonEmptyStringAndLiteral' => [
|
||||
'non-empty-string',
|
||||
[
|
||||
'non-empty-string',
|
||||
'"foo"',
|
||||
]
|
||||
],
|
||||
'combinLiteralAndNonEmptyString' => [
|
||||
'non-empty-string',
|
||||
[
|
||||
'"foo"',
|
||||
'non-empty-string'
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user