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:
parent
ac06ea659e
commit
7b4dbb1c85
@ -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
|
||||||
|
@ -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) {
|
||||||
|
@ -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>',
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user