Skip to content

Commit

Permalink
Remove unnecessary references to empty in TypeCombiner
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 15, 2021
1 parent 1f8546c commit 19fd10b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions src/Psalm/Internal/Type/TypeCombiner.php
Expand Up @@ -79,7 +79,7 @@ class TypeCombiner
* - so `int + string = int|string`
* - so `array<int> + array<string> = array<int|string>`
* - and `array<int> + string = array<int>|string`
* - and `array<empty> + array<empty> = array<empty>`
* - and `array<never> + array<never> = array<never>`
* - and `array<string> + array<empty> = array<string>`
* - and `array + array<string> = array<mixed>`
*
Expand Down Expand Up @@ -337,20 +337,17 @@ public static function combine(
$combination->value_types += $combination->named_object_types;
}

$has_empty = (int) (isset($combination->value_types['never']) || isset($combination->value_types['empty']));
$has_never = false;
$has_never = isset($combination->value_types['never']);

foreach ($combination->value_types as $type) {
if ($type instanceof TMixed
&& $combination->mixed_from_loop_isset
&& (count($combination->value_types) > (1 + $has_empty) || count($new_types) > $has_empty)
&& (count($combination->value_types) > (1 + (int) $has_never) || count($new_types) > (int) $has_never)
) {
continue;
}

if (($type instanceof TNever || $type instanceof TAssertionEmpty)
&& (count($combination->value_types) > 1 || count($new_types))
) {
if ($type instanceof TNever && (count($combination->value_types) > 1 || count($new_types))) {
$has_never = true;
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/TypeCombinationTest.php
Expand Up @@ -108,10 +108,10 @@ public function providerTestValidTypeCombination(): array
'null',
],
],
'mixedOrEmpty' => [
'mixedOrNever' => [
'mixed',
[
'empty',
'never',
'mixed',
],
],
Expand Down Expand Up @@ -205,7 +205,7 @@ public function providerTestValidTypeCombination(): array
'arrayStringOrEmptyArray' => [
'array<array-key, string>',
[
'array<empty>',
'array<never>',
'array<string>',
],
],
Expand All @@ -226,7 +226,7 @@ public function providerTestValidTypeCombination(): array
'arrayMixedOrEmpty' => [
'array<array-key, mixed>',
[
'array<empty>',
'array<never>',
'array<mixed>',
],
],
Expand Down

0 comments on commit 19fd10b

Please sign in to comment.