Skip to content
Permalink
Browse files

Fix #2613 - allow docblock-defined object-like as non-empty-array

  • Loading branch information
muglug committed Jan 14, 2020
1 parent 5d15ef0 commit ef3c2d30c91dffc764dedcf427891a6205e62f1c
Showing with 22 additions and 2 deletions.
  1. +12 −2 src/Psalm/Internal/Analyzer/TypeAnalyzer.php
  2. +10 −0 tests/AnnotationTest.php
@@ -2156,6 +2156,8 @@ private static function isMatchingTypeContainedBy(
|| !$container_type_part instanceof TNonEmptyList;
}

$prior_input_type_part = $input_type_part;

if (($input_type_part instanceof TArray
|| $input_type_part instanceof ObjectLike
|| $input_type_part instanceof TList
@@ -2293,8 +2295,16 @@ function ($carry, Type\Union $item) {

if ($container_type_part instanceof Type\Atomic\TNonEmptyArray
&& !$input_type_part instanceof Type\Atomic\TNonEmptyArray
&& !($input_type_part instanceof ObjectLike
&& ($input_type_part->sealed || $input_type_part->previous_value_type)
&& !($prior_input_type_part instanceof ObjectLike
&& ($prior_input_type_part->sealed
|| $prior_input_type_part->previous_value_type
|| \array_filter(
$prior_input_type_part->properties,
function ($prop_type) {
return !$prop_type->possibly_undefined;
}
)
)
)
) {
if ($all_types_contain) {
@@ -1046,6 +1046,16 @@ function getPerson_error(): array {
return json_decode($json, true);
}'
],
'allowDocblockDefinedObjectLikeArrayIntoNonEmpty' => [
'<?php
/** @param non-empty-array $_bar */
function foo(array $_bar) : void { }
/** @var array{0:list<string>, 1:list<int>} */
$bar = [[], []];
foo($bar);'
],
];
}

0 comments on commit ef3c2d3

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