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

Also check incremental overflows ref #691

This commit is contained in:
Matthew Brown 2018-04-24 23:12:01 -04:00
parent 35725267f9
commit 048a32e7b6
2 changed files with 31 additions and 0 deletions

View File

@ -199,6 +199,13 @@ class ExpressionChecker
if (isset($stmt->var->inferredType)) {
$stmt->inferredType = clone $stmt->var->inferredType;
$stmt->inferredType->from_calculation = true;
$var_id = self::getArrayVarId($stmt->var, null);
if ($var_id && isset($context->vars_in_scope[$var_id])) {
$context->vars_in_scope[$var_id] = $stmt->inferredType;
}
} else {
$stmt->inferredType = Type::getMixed();
}

View File

@ -349,6 +349,7 @@ class RedundantConditionTest extends TestCase
'<?php
function foo(int $x) : void {
$x = $x + 1;
if (!is_int($x)) {
echo "Is a float.";
} else {
@ -358,6 +359,29 @@ class RedundantConditionTest extends TestCase
function bar(int $x) : void {
$x = $x + 1;
if (is_float($x)) {
echo "Is a float.";
} else {
echo "Is an int.";
}
}',
],
'allowIntValueCheckAfterComparisonDueToOverflowInc' => [
'<?php
function foo(int $x) : void {
$x++;
if (!is_int($x)) {
echo "Is a float.";
} else {
echo "Is an int.";
}
}
function bar(int $x) : void {
$x++;
if (is_float($x)) {
echo "Is a float.";
} else {