mirror of
https://github.com/danog/psalm.git
synced 2024-11-29 20:28:59 +01:00
parent
f8e22ab7ac
commit
c54416090f
@ -3733,12 +3733,25 @@ class AssertionFinder
|
||||
|| $atomic_type instanceof Type\Atomic\TKeyedArray
|
||||
) {
|
||||
if ($atomic_type instanceof Type\Atomic\TKeyedArray) {
|
||||
$key_possibly_undefined = false;
|
||||
|
||||
foreach ($atomic_type->properties as $property_type) {
|
||||
if ($property_type->possibly_undefined) {
|
||||
$key_possibly_undefined = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$key_type = $atomic_type->getGenericKeyType();
|
||||
|
||||
if ($key_possibly_undefined) {
|
||||
$key_type->possibly_undefined = true;
|
||||
}
|
||||
} else {
|
||||
$key_type = $atomic_type->type_params[0];
|
||||
}
|
||||
|
||||
if ($key_type->allStringLiterals()) {
|
||||
if ($key_type->allStringLiterals() && !$key_type->possibly_undefined) {
|
||||
foreach ($key_type->getLiteralStrings() as $array_literal_type) {
|
||||
$literal_assertions[] = '=' . $array_literal_type->getId();
|
||||
}
|
||||
|
@ -299,6 +299,19 @@ class ArrayKeyExistsTest extends \Psalm\Tests\TestCase
|
||||
'MixedArgument',
|
||||
],
|
||||
],
|
||||
'arrayKeyExistsTwoVars' => [
|
||||
'<?php
|
||||
/**
|
||||
* @param array{a: string, b: string, c?: string} $info
|
||||
*/
|
||||
function getReason(array $info, string $key, string $value): bool {
|
||||
if (array_key_exists($key, $info) && $info[$key] === $value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user