Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix false positive ArgumentTypeCoercion for callback param #10454

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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