mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 17:52:45 +01:00
Throw error if we are accessing object-like array with int offset
This commit is contained in:
parent
b8ba6ffbf6
commit
c060a75b24
@ -3946,9 +3946,23 @@ class StatementsChecker
|
|||||||
elseif ($type instanceof Type\Generic && $value_index !== null) {
|
elseif ($type instanceof Type\Generic && $value_index !== null) {
|
||||||
$stmt->inferredType = $type->type_params[$value_index];
|
$stmt->inferredType = $type->type_params[$value_index];
|
||||||
}
|
}
|
||||||
elseif ($type instanceof Type\ObjectLike && $key_value && isset($type->properties[$key_value])) {
|
elseif ($type instanceof Type\ObjectLike) {
|
||||||
|
if ($key_value && isset($type->properties[$key_value])) {
|
||||||
$stmt->inferredType = clone $type->properties[$key_value];
|
$stmt->inferredType = clone $type->properties[$key_value];
|
||||||
}
|
}
|
||||||
|
elseif ($key_type->hasInt()) {
|
||||||
|
if (IssueBuffer::accepts(
|
||||||
|
new InvalidArrayAccess(
|
||||||
|
'Cannot access value on object-like variable $' . $var_id . ' using int offset - expecting string',
|
||||||
|
$this->checked_file_name,
|
||||||
|
$stmt->getLine()
|
||||||
|
),
|
||||||
|
$this->suppressed_issues
|
||||||
|
)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif ($type->isString()) {
|
elseif ($type->isString()) {
|
||||||
if ($key_type) {
|
if ($key_type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user