1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +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,13 +371,16 @@ class TypeCombination
$overwrite_empty_array, $overwrite_empty_array,
$allow_mixed_union $allow_mixed_union
); );
$generic_type_params[1] = Type::combineUnionTypes(
$generic_type_params[1], if (!$generic_type_params[1]->isMixed()) {
$objectlike_generic_type, $generic_type_params[1] = Type::combineUnionTypes(
$codebase, $generic_type_params[1],
$overwrite_empty_array, $objectlike_generic_type,
$allow_mixed_union $codebase,
); $overwrite_empty_array,
$allow_mixed_union
);
}
} }
if ($combination->array_always_filled if ($combination->array_always_filled

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>',
[ [