From 40ce0cf7d7fc026696ec90c677fd8b130e788d2c Mon Sep 17 00:00:00 2001 From: Yannick Gottschalk Date: Mon, 12 Jun 2023 15:24:30 +0200 Subject: [PATCH 1/2] Fixes #9827 --- src/Psalm/Internal/Type/TypeCombiner.php | 4 +++- tests/TypeCombinationTest.php | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 0daa9d29684..d091c239961 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -130,7 +130,9 @@ public static function combine( if (count($combination->value_types) === 1 && !count($combination->objectlike_entries) && (!$combination->array_type_params - || $combination->array_type_params[1]->isNever() + || ( $overwrite_empty_array + && $combination->array_type_params[1]->isNever() + ) ) && !$combination->builtin_type_params && !$combination->object_type_params diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index 2b85c551761..c2499ab96a3 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -338,6 +338,28 @@ public function providerTestValidTypeCombination(): array 'ArrayObject', ], ], + 'emptyArrayAndFalse' => [ + 'array|false', + [ + 'array', + 'false' + ] + ], + 'emptyArrayAndTrue' => [ + 'array|true', + [ + 'array', + 'true' + ] + ], + 'emptyArrayWithTrueAndFalse' => [ + 'array|bool', + [ + 'array', + 'true', + 'false' + ] + ], 'falseDestruction' => [ 'bool', [ From d11bb90c967f76011d2bc02438ca555a2ebe572f Mon Sep 17 00:00:00 2001 From: Yannick Gottschalk Date: Mon, 12 Jun 2023 15:29:22 +0200 Subject: [PATCH 2/2] Style fixes --- tests/TypeCombinationTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index c2499ab96a3..5a74bc01266 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -342,23 +342,23 @@ public function providerTestValidTypeCombination(): array 'array|false', [ 'array', - 'false' - ] + 'false', + ], ], 'emptyArrayAndTrue' => [ 'array|true', [ 'array', - 'true' - ] + 'true', + ], ], 'emptyArrayWithTrueAndFalse' => [ 'array|bool', [ 'array', 'true', - 'false' - ] + 'false', + ], ], 'falseDestruction' => [ 'bool',