1
0
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:
Matthew Brown 2016-10-03 16:40:46 -04:00
parent b8ba6ffbf6
commit c060a75b24

View File

@ -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) {