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

fix stub for array_combine + remove false in PHP8 + improve tests (#5395)

This commit is contained in:
orklah 2021-03-16 18:43:49 +01:00 committed by GitHub
parent 9d840ee87b
commit 1a3ff5676a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -66,7 +66,11 @@ function array_intersect_assoc(array $arr, array $arr2, array ...$arr3)
* @param array<mixed, TKey> $arr
* @param array<mixed, TValue> $arr2
*
* @return ($arr is non-empty-array ? non-empty-array<TKey, TValue>|false : array<empty, empty>|false)
* @return (
* PHP_MAJOR_VERSION is 8 ?
* ($arr is non-empty-array ? non-empty-array<TKey, TValue> : array<TKey, TValue>) :
* ($arr is non-empty-array ? non-empty-array<TKey, TValue>|false : array<TKey, TValue>|false
* )
* @psalm-ignore-falsable-return
* @psalm-pure
*/

View File

@ -159,13 +159,37 @@ class ArrayFunctionCallTest extends TestCase
'assertions' => [
'$c' => 'false|non-empty-array<string, int>',
],
'error_levels' => [],
'7.4',
],
'arrayCombineFalse' => [
'arrayCombinePHP8' => [
'<?php
$c = array_combine(["a", "b"], [1, 2, 3]);',
'assertions' => [
'$c' => 'non-empty-array<string, int>',
],
'error_levels' => [],
'8.0',
],
'arrayCombineNotMatching' => [
'<?php
$c = array_combine(["a", "b"], [1, 2, 3]);',
'assertions' => [
'$c' => 'false|non-empty-array<string, int>',
],
'error_levels' => [],
'7.4',
],
'arrayCombineDynamicParams' => [
'<?php
/** @return array<string> */
function getStrings(): array{ return []; }
/** @return array<int> */
function getInts(): array{ return []; }
$c = array_combine(getStrings(), getInts());',
'assertions' => [
'$c' => 'array<string, int>|false',
],
],
'arrayMergeIntArrays' => [
'<?php