mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Arithmetic operation between numeric and int or float gives int|float
This commit is contained in:
parent
ffbdaa80b1
commit
55245cf558
@ -667,11 +667,15 @@ class NonDivArithmeticOpAnalyzer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Mod) {
|
if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Mod) {
|
||||||
$result_type = Type::getInt();
|
$new_result_type = Type::getInt();
|
||||||
} elseif (!$result_type) {
|
|
||||||
$result_type = Type::getNumeric();
|
|
||||||
} else {
|
} else {
|
||||||
$result_type = Type::combineUnionTypes(Type::getNumeric(), $result_type);
|
$new_result_type = new Type\Union([new TFloat(), new TInt()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$result_type) {
|
||||||
|
$result_type = $new_result_type;
|
||||||
|
} else {
|
||||||
|
$result_type = Type::combineUnionTypes($new_result_type, $result_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
$has_valid_right_operand = true;
|
$has_valid_right_operand = true;
|
||||||
|
@ -640,6 +640,26 @@ class BinaryOperationTest extends TestCase
|
|||||||
return "foo" . $s1;
|
return "foo" . $s1;
|
||||||
}',
|
}',
|
||||||
],
|
],
|
||||||
|
'numericWithInt' => [
|
||||||
|
'<?php
|
||||||
|
/** @return numeric */
|
||||||
|
function getNumeric(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
$a = getNumeric();
|
||||||
|
$a++;
|
||||||
|
$b = getNumeric() * 2;
|
||||||
|
$c = 1 - getNumeric();
|
||||||
|
$d = 2;
|
||||||
|
$d -= getNumeric();
|
||||||
|
',
|
||||||
|
'assertions' => [
|
||||||
|
'$a' => 'float|int',
|
||||||
|
'$b' => 'float|int',
|
||||||
|
'$c' => 'float|int',
|
||||||
|
'$d' => 'float|int',
|
||||||
|
],
|
||||||
|
],
|
||||||
'encapsedStringWithIntIncludingLiterals' => [
|
'encapsedStringWithIntIncludingLiterals' => [
|
||||||
'<?php
|
'<?php
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user