From 1b854d6c3bcd5f263c96a29393dda7bb6e10f3c5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 1 Jun 2024 16:38:15 +0200 Subject: [PATCH] `array_fill_keys` expects array of array-key --- resources/functionMap.php | 4 +-- resources/functionMap_php80delta.php | 4 +-- .../CallToFunctionParametersRuleTest.php | 18 +++++++++++ .../Rules/Functions/data/bug-11111.php | 32 +++++++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tests/PHPStan/Rules/Functions/data/bug-11111.php diff --git a/resources/functionMap.php b/resources/functionMap.php index 6dce1358e9..b11e53d2bb 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -261,7 +261,7 @@ 'array_change_key_case' => ['array', 'input'=>'array', 'case='=>'int'], 'array_chunk' => ['list', 'input'=>'array', 'size'=>'positive-int', 'preserve_keys='=>'bool'], 'array_column' => ['array', 'array'=>'array', 'column_key'=>'mixed', 'index_key='=>'mixed'], -'array_combine' => ['array|false', 'keys'=>'array', 'values'=>'array'], +'array_combine' => ['array|false', 'keys'=>'array', 'values'=>'array'], 'array_count_values' => ['array', 'input'=>'array'], 'array_diff' => ['array', 'arr1'=>'array', 'arr2'=>'array', '...args='=>'array'], 'array_diff_assoc' => ['array', 'arr1'=>'array', 'arr2'=>'array', '...args='=>'array'], @@ -271,7 +271,7 @@ 'array_diff_ukey' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'key_comp_func'=>'callable(mixed,mixed):int'], 'array_diff_ukey\'1' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable(mixed,mixed):int', '...rest='=>'array|callable(mixed,mixed):int'], 'array_fill' => ['array', 'start_key'=>'int', 'num'=>'int', 'val'=>'mixed'], -'array_fill_keys' => ['array', 'keys'=>'array', 'val'=>'mixed'], +'array_fill_keys' => ['array', 'keys'=>'array', 'val'=>'mixed'], 'array_filter' => ['array', 'input'=>'array', 'callback='=>'callable(mixed,mixed):bool|callable(mixed):bool', 'flag='=>'int'], 'array_flip' => ['array', 'input'=>'array'], 'array_intersect' => ['array', 'arr1'=>'array', 'arr2'=>'array', '...args='=>'array'], diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index fd85f6750c..f01a267170 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -21,7 +21,7 @@ */ return [ 'new' => [ - 'array_combine' => ['associative-array', 'keys'=>'string[]|int[]', 'values'=>'array'], + 'array_combine' => ['associative-array', 'keys'=>'array', 'values'=>'array'], 'base64_decode' => ['string', 'string'=>'string', 'strict='=>'false'], 'base64_decode\'1' => ['string|false', 'string'=>'string', 'strict='=>'true'], 'bcdiv' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], @@ -161,7 +161,7 @@ 'xmlwriter_write_raw' => ['bool', 'xmlwriter'=>'XMLWriter', 'content'=>'string'], ], 'old' => [ - 'array_combine' => ['associative-array|false', 'keys'=>'string[]|int[]', 'values'=>'array'], + 'array_combine' => ['associative-array|false', 'keys'=>'array', 'values'=>'array'], 'bcdiv' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['?string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 880a576771..2b043c3039 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -1687,4 +1687,22 @@ public function testBug10974(): void $this->analyse([__DIR__ . '/data/bug-10974.php'], []); } + public function testBug11111(): void + { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped('Test requires PHP 8.1.'); + } + + $this->analyse([__DIR__ . '/data/bug-11111.php'], [ + [ + 'Parameter #1 $keys of function array_fill_keys expects array<(int|string)>, array given.', + 24, + ], + [ + 'Parameter #1 $keys of function array_combine expects array<(int|string)>, array given.', + 28, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-11111.php b/tests/PHPStan/Rules/Functions/data/bug-11111.php new file mode 100644 index 0000000000..8222175ced --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-11111.php @@ -0,0 +1,32 @@ +