1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Emit InvalidOperand if both sides are not numeric

This commit is contained in:
Matt Brown 2018-03-08 14:30:40 -05:00
parent 56bdb924f5
commit 19ee843d6c
2 changed files with 17 additions and 1 deletions

View File

@ -769,6 +769,17 @@ class BinaryOpChecker
)) {
// fall through
}
} else {
if ($statements_source && IssueBuffer::accepts(
new InvalidOperand(
'Cannot perform a numeric operation with non-numeric types ' . $left_type_part
. ' and ' . $right_type_part,
new CodeLocation($statements_source, $parent)
),
$statements_source->getSuppressedIssues()
)) {
// fall through
}
}
}
}

View File

@ -23,7 +23,7 @@ class BinaryOperationTest extends TestCase
'numericAddition' => [
'<?php
$a = "5";
if (is_numeric($a)) {
$b = $a + 4;
}',
@ -71,6 +71,11 @@ class BinaryOperationTest extends TestCase
'error_levels' => [],
'strict_mode' => true,
],
'additionWithClassInWeakMode' => [
'<?php
$a = "hi" + (new stdClass);',
'error_message' => 'InvalidOperand',
],
];
}
}