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,
$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

View File

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

View File

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