From 19fd10ba7b78f341af72bb5486b46bd49e0b897a Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 15 Dec 2021 11:31:59 +0000 Subject: [PATCH] Remove unnecessary references to empty in TypeCombiner --- src/Psalm/Internal/Type/TypeCombiner.php | 11 ++++------- tests/TypeCombinationTest.php | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index a693f38896d..432432b7ba4 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -79,7 +79,7 @@ class TypeCombiner * - so `int + string = int|string` * - so `array + array = array` * - and `array + string = array|string` - * - and `array + array = array` + * - and `array + array = array` * - and `array + array = array` * - and `array + array = array` * @@ -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; } diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index f1330e20717..fff9eaf8992 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -108,10 +108,10 @@ public function providerTestValidTypeCombination(): array 'null', ], ], - 'mixedOrEmpty' => [ + 'mixedOrNever' => [ 'mixed', [ - 'empty', + 'never', 'mixed', ], ], @@ -205,7 +205,7 @@ public function providerTestValidTypeCombination(): array 'arrayStringOrEmptyArray' => [ 'array', [ - 'array', + 'array', 'array', ], ], @@ -226,7 +226,7 @@ public function providerTestValidTypeCombination(): array 'arrayMixedOrEmpty' => [ 'array', [ - 'array', + 'array', 'array', ], ],