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:
parent
56bdb924f5
commit
19ee843d6c
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user