mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #266 - do better analysis of array_rand
And also have better fallback when accessing string key on object-like array
This commit is contained in:
parent
a50783404f
commit
750d18d20a
@ -1130,6 +1130,8 @@ class FetchChecker
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($key_type->hasString()) {
|
||||
$stmt->inferredType = $type->getGenericTypeParam();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -107,3 +107,11 @@ function array_pop(array $arr) {}
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
function array_reverse(array $arr) {}
|
||||
|
||||
/**
|
||||
* @template TKey
|
||||
*
|
||||
* @param array<TKey, mixed> $arr
|
||||
* @return TKey
|
||||
*/
|
||||
function array_rand(array $arr) {}
|
||||
|
@ -281,6 +281,18 @@ class FunctionCallTest extends TestCase
|
||||
fooFoo($a->foo);
|
||||
fooFoo($b);',
|
||||
],
|
||||
'arrayRand' => [
|
||||
'<?php
|
||||
$vars = ["x" => "a", "y" => "b"];
|
||||
$c = array_rand($vars);
|
||||
$d = $vars[$c];',
|
||||
|
||||
'assertions' => [
|
||||
'$vars' => 'array{x:string, y:string}',
|
||||
'$c' => 'string',
|
||||
'$d' => 'string',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user