mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1826 - don’t allow mixed unions when combining with object-like array
This commit is contained in:
parent
ac06ea659e
commit
7b4dbb1c85
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -379,6 +379,13 @@ class TypeCombinationTest extends TestCase
|
||||
'string',
|
||||
],
|
||||
],
|
||||
'combineMixedArrayWithObjectLike' => [
|
||||
'array<array-key, mixed>',
|
||||
[
|
||||
'array{a: int}',
|
||||
'array',
|
||||
],
|
||||
],
|
||||
'traversableAorB' => [
|
||||
'Traversable<mixed, A|B>',
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user