1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix addition of int and string type

This commit is contained in:
Matt Brown 2020-10-07 18:01:41 -04:00 committed by Daniil Gentili
parent 5c1fcf403c
commit f1be27b18a
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 9 additions and 3 deletions

View File

@ -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;

View File

@ -296,6 +296,14 @@ class BinaryOperationTest extends TestCase
*/
function test(int $tickedTimes): void {}'
],
'numericPlusIntegerIsIntOrFloat' => [
'<?php
/** @param numeric-string $s */
function foo(string $s) : void {
$s = $s + 1;
if (is_int($s)) {}
}'
],
];
}