From 7b4dbb1c85d1a924bccb449f93a77d770ec5f308 Mon Sep 17 00:00:00 2001 From: Brown Date: Thu, 20 Jun 2019 20:13:36 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20#1826=20-=20don=E2=80=99t=20allow=20mixed?= =?UTF-8?q?=20unions=20when=20combining=20with=20object-like=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Psalm/Internal/Type/TypeCombination.php | 17 ++++++++++------- tests/ArrayAccessTest.php | 11 ----------- tests/TypeCombinationTest.php | 7 +++++++ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeCombination.php b/src/Psalm/Internal/Type/TypeCombination.php index b50038a86..4af1c1678 100644 --- a/src/Psalm/Internal/Type/TypeCombination.php +++ b/src/Psalm/Internal/Type/TypeCombination.php @@ -371,13 +371,16 @@ class TypeCombination $overwrite_empty_array, $allow_mixed_union ); - $generic_type_params[1] = Type::combineUnionTypes( - $generic_type_params[1], - $objectlike_generic_type, - $codebase, - $overwrite_empty_array, - $allow_mixed_union - ); + + if (!$generic_type_params[1]->isMixed()) { + $generic_type_params[1] = Type::combineUnionTypes( + $generic_type_params[1], + $objectlike_generic_type, + $codebase, + $overwrite_empty_array, + $allow_mixed_union + ); + } } if ($combination->array_always_filled diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index 970e88849..3fa528668 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -672,17 +672,6 @@ class ArrayAccessTest extends TestCase }', 'error_message' => 'PossiblyInvalidArrayOffset', ], - 'possiblyInvalidMixedUnionArrayOffset' => [ - ' 'PossiblyInvalidArrayOffset', - 'error_level' => ['MixedArrayAssignment'], - ], 'arrayAccessOnIterable' => [ ' [ + 'array', + [ + 'array{a: int}', + 'array', + ], + ], 'traversableAorB' => [ 'Traversable', [