From 07224e7d31ed2c259d013662b1fdfcb1ecbd0071 Mon Sep 17 00:00:00 2001 From: marcosh Date: Tue, 7 Dec 2021 11:52:13 +0100 Subject: [PATCH 1/2] abs should always return a positive integer --- stubs/CoreGenericFunctions.phpstub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index 0c0c01f5678..4b56b4997bb 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -423,7 +423,7 @@ function gettimeofday(bool $as_float = false) {} * @psalm-pure * * @param numeric $num - * @return ($num is int ? int : ($num is float ? float : int|float)) + * @return ($num is int ? positive-int|0 : ($num is float ? float : positive-int|0|float)) */ function abs($num) {} From 9c4187fd2f59c3c4a9fd5bdb29449865f0ab32ff Mon Sep 17 00:00:00 2001 From: marcosh Date: Tue, 7 Dec 2021 12:00:52 +0100 Subject: [PATCH 2/2] fix abs tests --- tests/FunctionCallTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 8bc32b714a2..1197d861e04 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -47,9 +47,9 @@ function fooFoo(array $a = []): void { $c = $_GET["c"]; $c = is_numeric($c) ? abs($c) : null;', 'assertions' => [ - '$a' => 'int', + '$a' => 'int|positive-int', '$b' => 'float', - '$c' => 'float|int|null', + '$c' => 'float|int|null|positive-int', ], 'error_levels' => ['MixedAssignment', 'MixedArgument'], ],