1
0
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:
Bruce Weirdan 2021-07-25 13:56:48 +03:00 committed by GitHub
commit 82dfbbc12e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

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

View File

@ -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
/**