From 7dfa37beb26e66734093cd3b498d98e781c9faee Mon Sep 17 00:00:00 2001 From: Brown Date: Sat, 11 Apr 2020 17:50:24 -0400 Subject: [PATCH] Improve ergonomics of array assignment --- src/Psalm/Internal/Type/TypeCombination.php | 2 +- tests/ArrayAssignmentTest.php | 19 ++++++++++++++++++- tests/TypeCombinationTest.php | 15 +++++++++++---- tests/TypeReconciliation/ReconcilerTest.php | 2 +- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeCombination.php b/src/Psalm/Internal/Type/TypeCombination.php index 872430805..d6e113625 100644 --- a/src/Psalm/Internal/Type/TypeCombination.php +++ b/src/Psalm/Internal/Type/TypeCombination.php @@ -428,7 +428,7 @@ class TypeCombination $allow_mixed_union ); - if ($allow_mixed_union || !$generic_type_params[1]->isMixed()) { + if (!$generic_type_params[1]->isMixed()) { $generic_type_params[1] = Type::combineUnionTypes( $generic_type_params[1], $objectlike_generic_type, diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index db777f7b8..7404e6bfa 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -1402,9 +1402,26 @@ class ArrayAssignmentTest extends TestCase $arr["hello"]["goodbye"] = 5; }', [ - '$arr' => 'array', + '$arr' => 'array', ] ], + 'dontUpdateMixedArrayWithStringKey' => [ + ' [ - 'array', + 'array', [ 'array{a: int}', 'array', @@ -523,21 +523,28 @@ class TypeCombinationTest extends TestCase ], ], 'combineCallableArrayAndArray' => [ - 'array', + 'array', [ 'callable-array{class-string, string}', 'array', ], ], - 'combineObjectLikeArrayAndArray' => [ + 'combineGenericArrayAndMixedArray' => [ 'array', + [ + 'array', + 'array', + ], + ], + 'combineObjectLikeArrayAndArray' => [ + 'array', [ 'array{hello: int}', 'array', ], ], 'combineObjectLikeArrayAndNestedArray' => [ - 'array', + 'array', [ 'array{hello: array{goodbye: int}}', 'array', diff --git a/tests/TypeReconciliation/ReconcilerTest.php b/tests/TypeReconciliation/ReconcilerTest.php index 46724212c..61a1b3096 100644 --- a/tests/TypeReconciliation/ReconcilerTest.php +++ b/tests/TypeReconciliation/ReconcilerTest.php @@ -139,7 +139,7 @@ class ReconcilerTest extends \Psalm\Tests\TestCase 'iterableToArray' => ['array', 'array', 'iterable'], 'iterableToTraversable' => ['Traversable', 'Traversable', 'iterable'], 'callableToCallableArray' => ['callable-array{0: class-string|object, 1: string}', 'array', 'callable'], - 'callableOrArrayToCallableArray' => ['array', 'array', 'callable|array'], + 'callableOrArrayToCallableArray' => ['array', 'array', 'callable|array'], 'traversableToIntersection' => ['Countable&Traversable', 'Traversable', 'Countable'], 'iterableWithoutParamsToTraversableWithoutParams' => ['Traversable', '!array', 'iterable'], 'iterableWithParamsToTraversableWithParams' => ['Traversable', '!array', 'iterable'],