mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #3010 - prevent false-negative after calling isset on possibly-false array
This commit is contained in:
parent
010b805397
commit
25bd2ed5fb
@ -514,7 +514,9 @@ class Reconciler
|
||||
|
||||
$new_base_type_candidate->possibly_undefined = true;
|
||||
}
|
||||
} elseif ($existing_key_type_part instanceof Type\Atomic\TNull) {
|
||||
} elseif ($existing_key_type_part instanceof Type\Atomic\TNull
|
||||
|| $existing_key_type_part instanceof Type\Atomic\TFalse
|
||||
) {
|
||||
$new_base_type_candidate = Type::getNull();
|
||||
} elseif ($existing_key_type_part instanceof Type\Atomic\TClassStringMap) {
|
||||
return Type::getMixed();
|
||||
@ -552,10 +554,10 @@ class Reconciler
|
||||
$codebase
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$existing_keys[$new_base_key] = $new_base_type;
|
||||
}
|
||||
}
|
||||
|
||||
$base_key = $new_base_key;
|
||||
} elseif ($divider === '->' || $divider === '::$') {
|
||||
|
@ -980,6 +980,23 @@ class IssetTest extends \Psalm\Tests\TestCase
|
||||
}',
|
||||
'error_message' => 'PossiblyUndefinedArrayOffset',
|
||||
],
|
||||
'accessAfterIssetCheckOnFalsableArray' => [
|
||||
'<?php
|
||||
/**
|
||||
* @return array{b?: string}|false
|
||||
*/
|
||||
function returnPossiblyFalseArray() {
|
||||
return rand(0, 1) ? false : (rand(0, 1) ? ["b" => "hello"] : []);
|
||||
}
|
||||
|
||||
function foo() : void {
|
||||
$arr = returnPossiblyFalseArray();
|
||||
/** @psalm-suppress PossiblyInvalidArrayAccess */
|
||||
if (!isset($arr["b"])) {}
|
||||
echo $arr["b"];
|
||||
}',
|
||||
'error_message' => 'PossiblyInvalidArrayAccess',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user