Skip to content

Commit

Permalink
Merge pull request #10454 from kkmuffme/unsealed-not-nonempty-callabl…
Browse files Browse the repository at this point in the history
…e-param-should-be-valid

fix false positive ArgumentTypeCoercion for callback param
  • Loading branch information
orklah committed Dec 12, 2023
2 parents a5e1579 + 3c045b3 commit 1df5b35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Psalm/Internal/Type/Comparator/ArrayTypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ public static function isContainedBy(
return true;
}

if ($container_type_part instanceof TKeyedArray
&& $input_type_part instanceof TArray
&& !$container_type_part->is_list
&& !$container_type_part->isNonEmpty()
&& !$container_type_part->isSealed()
&& $input_type_part->equals(
$container_type_part->getGenericArrayType($container_type_part->isNonEmpty()),
false,
)
) {
return true;
}

if ($container_type_part instanceof TKeyedArray
&& $input_type_part instanceof TArray
) {
Expand Down
16 changes: 16 additions & 0 deletions tests/CallableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,22 @@ function addHandler(string $_message, callable $_handler): void {}
return [1, 2, 3];
});',
],
'unsealedAllOptionalCbParam' => [
'code' => '<?php
/**
* @param callable(array<string, string>) $arg
* @return void
*/
function foo($arg) {}
/**
* @param array{a?: string}&array<string, string> $cb_arg
* @return void
*/
function bar($cb_arg) {}
foo("bar");',
],
];
}

Expand Down

0 comments on commit 1df5b35

Please sign in to comment.