Skip to content

Commit

Permalink
Merge pull request #6169 from orklah/numeric-strictBinaryOperands
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan authored Jul 24, 2021
2 parents 198fdf8 + 1a41ee4 commit 3caceb7
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,19 @@ private static function analyzeNonDivOperands(
if (($left_type_part instanceof TNumeric || $right_type_part instanceof TNumeric)
&& ($left_type_part->isNumericType() && $right_type_part->isNumericType())
) {
if ($config->strict_binary_operands) {
if ($statements_source && IssueBuffer::accepts(
new InvalidOperand(
'Cannot process different numeric types together in strict binary operands mode, '.
'please cast explicitly',
new CodeLocation($statements_source, $parent)
),
$statements_source->getSuppressedIssues()
)) {
// fall through
}
}

if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Mod) {
$result_type = Type::getInt();
} elseif (!$result_type) {
Expand Down Expand Up @@ -753,7 +766,8 @@ private static function analyzeNonDivOperands(
if ($config->strict_binary_operands) {
if ($statements_source && IssueBuffer::accepts(
new InvalidOperand(
'Cannot add ints to floats',
'Cannot process ints and floats in strict binary operands mode, '.
'please cast explicitly',
new CodeLocation($statements_source, $parent)
),
$statements_source->getSuppressedIssues()
Expand All @@ -780,7 +794,8 @@ private static function analyzeNonDivOperands(
if ($config->strict_binary_operands) {
if ($statements_source && IssueBuffer::accepts(
new InvalidOperand(
'Cannot add numeric types together, please cast explicitly',
'Cannot process numeric types together in strict operands mode, '.
'please cast explicitly',
new CodeLocation($statements_source, $parent)
),
$statements_source->getSuppressedIssues()
Expand Down

0 comments on commit 3caceb7

Please sign in to comment.