mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #6167 from orklah/non-div-with-numeric-and-int
This commit is contained in:
commit
82dfbbc12e
@ -679,11 +679,15 @@ class NonDivArithmeticOpAnalyzer
|
||||
}
|
||||
|
||||
if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Mod) {
|
||||
$result_type = Type::getInt();
|
||||
} elseif (!$result_type) {
|
||||
$result_type = Type::getNumeric();
|
||||
$new_result_type = Type::getInt();
|
||||
} 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;
|
||||
|
@ -640,6 +640,26 @@ class BinaryOperationTest extends TestCase
|
||||
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' => [
|
||||
'<?php
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user