mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #4791 - only generate special has-array-key assertions for unknown key types
This commit is contained in:
parent
524084a64c
commit
9423324d65
@ -380,7 +380,11 @@ class Reconciler
|
||||
if ($type[0][0] === 'array-key-exists') {
|
||||
$key_parts = Reconciler::breakUpPathIntoParts($nk);
|
||||
|
||||
if (count($key_parts) === 4 && $key_parts[1] === '[') {
|
||||
if (count($key_parts) === 4
|
||||
&& $key_parts[1] === '['
|
||||
&& $key_parts[2][0] !== '\''
|
||||
&& !\is_numeric($key_parts[2])
|
||||
) {
|
||||
if (isset($new_types[$key_parts[2]])) {
|
||||
$new_types[$key_parts[2]][] = ['=in-array-' . $key_parts[0]];
|
||||
} else {
|
||||
|
@ -362,6 +362,21 @@ class ArrayKeyExistsTest extends \Psalm\Tests\TestCase
|
||||
}',
|
||||
'error_message' => 'PossiblyUndefinedArrayOffset',
|
||||
],
|
||||
'dontCreateWeirdString' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-param array{inner:string} $options
|
||||
*/
|
||||
function go(array $options): void {
|
||||
if (!array_key_exists(\'size\', $options)) {
|
||||
throw new Exception(\'bad\');
|
||||
}
|
||||
|
||||
/** @psalm-suppress MixedArgument */
|
||||
echo $options[\'\\\'size\\\'\'];
|
||||
}',
|
||||
'error_message' => 'InvalidArrayOffset',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user