mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
dont combine empty string with numeric-string
Fix https://github.com/vimeo/psalm/issues/6646
This commit is contained in:
parent
93c7a8fd63
commit
5fccb33938
@ -1080,6 +1080,9 @@ final class TypeCombiner
|
|||||||
|
|
||||||
if ($has_only_numeric_strings) {
|
if ($has_only_numeric_strings) {
|
||||||
$combination->value_types['string'] = $type;
|
$combination->value_types['string'] = $type;
|
||||||
|
} elseif (count($combination->strings) === 1 && !$has_only_non_empty_strings) {
|
||||||
|
$combination->value_types['string'] = $type;
|
||||||
|
return;
|
||||||
} elseif ($has_only_non_empty_strings) {
|
} elseif ($has_only_non_empty_strings) {
|
||||||
$combination->value_types['string'] = new TNonEmptyString();
|
$combination->value_types['string'] = new TNonEmptyString();
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,6 +88,38 @@ class TypeCombinationTest extends TestCase
|
|||||||
}
|
}
|
||||||
',
|
',
|
||||||
],
|
],
|
||||||
|
'emptyStringNumericStringDontCombine' => [
|
||||||
|
'code' => '<?php
|
||||||
|
/**
|
||||||
|
* @param numeric-string $arg
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function takesNumeric($arg) {}
|
||||||
|
|
||||||
|
$b = rand(0, 10);
|
||||||
|
$a = $b < 5 ? "" : (string) $b;
|
||||||
|
if ($a !== "") {
|
||||||
|
takesNumeric($a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var ""|numeric-string $c */
|
||||||
|
if (is_numeric($c)) {
|
||||||
|
takesNumeric($c);
|
||||||
|
}',
|
||||||
|
],
|
||||||
|
'emptyStringNumericStringDontCombineNegation' => [
|
||||||
|
'code' => '<?php
|
||||||
|
/**
|
||||||
|
* @param ""|"hello" $arg
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function takesLiteralString($arg) {}
|
||||||
|
|
||||||
|
/** @var ""|numeric-string $c */
|
||||||
|
if (!is_numeric($c)) {
|
||||||
|
takesLiteralString($c);
|
||||||
|
}',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user