mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #4169 - add appropriate bounds check
This commit is contained in:
parent
3f8c91a64e
commit
09d22cb05c
@ -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;
|
||||
}
|
||||
|
@ -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> */
|
||||
|
Loading…
x
Reference in New Issue
Block a user