1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #4169 - add appropriate bounds check

This commit is contained in:
Brown 2020-09-12 11:33:26 -04:00
parent 3f8c91a64e
commit 09d22cb05c
2 changed files with 11 additions and 2 deletions

View File

@ -2767,7 +2767,7 @@ class AssertionFinder
)
) {
$max_count = $conditional->right->value -
($conditional instanceof PhpParser\Node\Expr\BinaryOp\Smaller ? 0 : 1);
($conditional instanceof PhpParser\Node\Expr\BinaryOp\Smaller ? 1 : 0);
return self::ASSIGNMENT_TO_RIGHT;
}
@ -2789,7 +2789,7 @@ class AssertionFinder
)
) {
$max_count = $conditional->left->value -
($conditional instanceof PhpParser\Node\Expr\BinaryOp\Greater ? 0 : 1);
($conditional instanceof PhpParser\Node\Expr\BinaryOp\Greater ? 1 : 0);
return self::ASSIGNMENT_TO_LEFT;
}

View File

@ -419,6 +419,15 @@ class ArrayFunctionCallTest extends TestCase
'$b' => 'int',
],
],
'arrayPopNonEmptyAfterCountLessThanEqualToOne' => [
'<?php
/** @var list<int> */
$a = [1, 2, 3];
$b = 5;
if (count($a) <= 1) {
echo $a[0];
}',
],
'arrayPopNonEmptyAfterArrayAddition' => [
'<?php
/** @var array<string, int> */