Skip to content
Permalink
Browse files

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

…array
  • Loading branch information...
muglug committed Jun 21, 2019
1 parent ac06ea6 commit 7b4dbb1c85d1a924bccb449f93a77d770ec5f308
Showing with 17 additions and 18 deletions.
  1. +10 −7 src/Psalm/Internal/Type/TypeCombination.php
  2. +0 −11 tests/ArrayAccessTest.php
  3. +7 −0 tests/TypeCombinationTest.php
@@ -371,13 +371,16 @@ function (Type\Union $type) : bool {
$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 @@ function foo(array $a, $key) : void {
}',
'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 @@ public function providerTestValidTypeCombination()
'string',
],
],
'combineMixedArrayWithObjectLike' => [
'array<array-key, mixed>',
[
'array{a: int}',
'array',
],
],
'traversableAorB' => [
'Traversable<mixed, A|B>',
[

0 comments on commit 7b4dbb1

Please sign in to comment.
You can’t perform that action at this time.