1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #3092 - round always returns a float

This commit is contained in:
Brown 2020-04-09 23:31:26 -04:00
parent f4a6b24e34
commit fea1310d67
2 changed files with 0 additions and 39 deletions

View File

@ -226,27 +226,6 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
break;
case 'round':
if (isset($call_args[1])) {
$second_arg = $call_args[1]->value;
if (($second_arg_type = $statements_analyzer->node_data->getType($second_arg))
&& $second_arg_type->isSingleIntLiteral()
) {
switch ($second_arg_type->getSingleIntLiteral()->value) {
case 0:
return Type::getInt(true);
default:
return Type::getFloat();
}
}
return new Type\Union([new Type\Atomic\TInt, new Type\Atomic\TFloat]);
}
return Type::getInt(true);
case 'get_parent_class':
// this is unreliable, as it's hard to know exactly what's wanted - attempted this in
// https://github.com/vimeo/psalm/commit/355ed831e1c69c96bbf9bf2654ef64786cbe9fd7

View File

@ -844,24 +844,6 @@ class FunctionCallTest extends TestCase
foo();
}',
],
'round' => [
'<?php
$a = round(4.6);
$b = round(3.6, 0);
$c = round(3.0, 1);
$d = round(3.1, 2);
/** @var int */
$sig = 1;
$e = round(3.1, $sig);',
'assertions' => [
'$a' => 'int',
'$b' => 'int',
'$c' => 'float',
'$d' => 'float',
'$e' => 'float|int',
],
],
'hashInit70' => [
'<?php
$h = hash_init("sha256");',