1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 13:51:54 +01:00

Merge pull request #10454 from kkmuffme/unsealed-not-nonempty-callable-param-should-be-valid

fix false positive ArgumentTypeCoercion for callback param
This commit is contained in:
orklah 2023-12-12 21:26:24 +01:00 committed by GitHub
commit 1df5b3580b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -49,6 +49,19 @@ final class ArrayTypeComparator
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
) {

View File

@ -1892,6 +1892,22 @@ class CallableTest extends TestCase
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");',
],
];
}