From f1be27b18a772cfa066170b30ea4073be89ee49b Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Wed, 7 Oct 2020 18:01:41 -0400 Subject: [PATCH] Fix addition of int and string type --- .../Expression/BinaryOp/NonDivArithmeticOpAnalyzer.php | 4 +--- tests/BinaryOperationTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/NonDivArithmeticOpAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/NonDivArithmeticOpAnalyzer.php index d223a047f..6d52fa53a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/NonDivArithmeticOpAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/NonDivArithmeticOpAnalyzer.php @@ -668,10 +668,8 @@ class NonDivArithmeticOpAnalyzer if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Mod) { $result_type = Type::getInt(); - } elseif (!$result_type) { - $result_type = Type::getFloat(); } else { - $result_type = Type::combineUnionTypes(Type::getFloat(), $result_type); + $result_type = new Type\Union([new Type\Atomic\TInt, new Type\Atomic\TFloat]); } $has_valid_right_operand = true; diff --git a/tests/BinaryOperationTest.php b/tests/BinaryOperationTest.php index 3059bb329..124daa62d 100644 --- a/tests/BinaryOperationTest.php +++ b/tests/BinaryOperationTest.php @@ -296,6 +296,14 @@ class BinaryOperationTest extends TestCase */ function test(int $tickedTimes): void {}' ], + 'numericPlusIntegerIsIntOrFloat' => [ + '