1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #1180 - array key maths was wrong

This commit is contained in:
Matthew Brown 2019-01-08 09:56:54 -05:00
parent dfba6e0dec
commit a89a201c71
2 changed files with 8 additions and 1 deletions

View File

@ -90,7 +90,7 @@ class ArrayAnalyzer
$item_key_value = $item->key->inferredType->getSingleIntLiteral()->value;
if ($item_key_value > $int_offset + $int_offset_diff) {
$int_offset_diff = $item_key_value - ($int_offset + $int_offset_diff);
$int_offset_diff = $item_key_value - $int_offset;
}
}
}

View File

@ -1010,6 +1010,13 @@ class ArrayAssignmentTest extends TestCase
$arr = [1 => 0, 1, 2, 3];
$arr = [1 => "one", 2 => "two", "three"];',
],
'noDuplicateImplicitIntArrayKeyLargeOffset' => [
'<?php
$arr = [
48 => "A",
95 => "a", "b",
];',
],
'constArrayAssignment' => [
'<?php
const BAR = 2;