mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix crash for empty string array access
This commit is contained in:
parent
4f770d356e
commit
7f7125f334
@ -642,13 +642,17 @@ class ArrayFetchAnalyzer
|
||||
if ($type instanceof TSingleLetter) {
|
||||
$valid_offset_type = Type::getInt(false, 0);
|
||||
} elseif ($type instanceof TLiteralString) {
|
||||
$valid_offsets = [];
|
||||
if (!strlen($type->value)) {
|
||||
$valid_offset_type = Type::getEmpty();
|
||||
} else {
|
||||
$valid_offsets = [];
|
||||
|
||||
for ($i = -strlen($type->value), $l = strlen($type->value); $i < $l; $i++) {
|
||||
$valid_offsets[] = new TLiteralInt($i);
|
||||
for ($i = -strlen($type->value), $l = strlen($type->value); $i < $l; $i++) {
|
||||
$valid_offsets[] = new TLiteralInt($i);
|
||||
}
|
||||
|
||||
$valid_offset_type = new Type\Union($valid_offsets);
|
||||
}
|
||||
|
||||
$valid_offset_type = new Type\Union($valid_offsets);
|
||||
} else {
|
||||
$valid_offset_type = Type::getInt();
|
||||
}
|
||||
|
@ -571,6 +571,12 @@ class ArrayAccessTest extends TestCase
|
||||
echo $a[-6];',
|
||||
'error_message' => 'InvalidArrayOffset',
|
||||
],
|
||||
'emptyStringAccess' => [
|
||||
'<?php
|
||||
$a = "";
|
||||
echo $a[0];',
|
||||
'error_message' => 'InvalidArrayOffset',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user