1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #1826 - don’t allow mixed unions when combining with object-like array

This commit is contained in:
Brown 2019-06-20 20:13:36 -04:00
parent ac06ea659e
commit 7b4dbb1c85
3 changed files with 17 additions and 18 deletions

View File

@ -371,6 +371,8 @@ class TypeCombination
$overwrite_empty_array, $overwrite_empty_array,
$allow_mixed_union $allow_mixed_union
); );
if (!$generic_type_params[1]->isMixed()) {
$generic_type_params[1] = Type::combineUnionTypes( $generic_type_params[1] = Type::combineUnionTypes(
$generic_type_params[1], $generic_type_params[1],
$objectlike_generic_type, $objectlike_generic_type,
@ -379,6 +381,7 @@ class TypeCombination
$allow_mixed_union $allow_mixed_union
); );
} }
}
if ($combination->array_always_filled if ($combination->array_always_filled
|| ($combination->array_sometimes_filled && $overwrite_empty_array) || ($combination->array_sometimes_filled && $overwrite_empty_array)

View File

@ -672,17 +672,6 @@ class ArrayAccessTest extends TestCase
}', }',
'error_message' => 'PossiblyInvalidArrayOffset', 'error_message' => 'PossiblyInvalidArrayOffset',
], ],
'possiblyInvalidMixedUnionArrayOffset' => [
'<?php
function foo(?array $index): void {
if (!$index) {
$index = ["foo", []];
}
$index[1][] = "bar";
}',
'error_message' => 'PossiblyInvalidArrayOffset',
'error_level' => ['MixedArrayAssignment'],
],
'arrayAccessOnIterable' => [ 'arrayAccessOnIterable' => [
'<?php '<?php
function foo(iterable $i) { function foo(iterable $i) {

View File

@ -379,6 +379,13 @@ class TypeCombinationTest extends TestCase
'string', 'string',
], ],
], ],
'combineMixedArrayWithObjectLike' => [
'array<array-key, mixed>',
[
'array{a: int}',
'array',
],
],
'traversableAorB' => [ 'traversableAorB' => [
'Traversable<mixed, A|B>', 'Traversable<mixed, A|B>',
[ [