Commit 193a0db 1 parent c82191b commit 193a0db Copy full SHA for 193a0db
File tree 2 files changed +14
-1
lines changed
src/Psalm/Internal/Analyzer/Statements/Expression
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 20
20
use Psalm \Type \Union ;
21
21
use RuntimeException ;
22
22
23
+ use function is_int ;
24
+
23
25
/**
24
26
* @internal
25
27
*/
@@ -51,7 +53,9 @@ public static function analyze(
51
53
continue ;
52
54
}
53
55
if ($ type_part instanceof TLiteralInt) {
54
- $ type_part = new TLiteralInt (-$ type_part ->value );
56
+ /** @var int|float $value */
57
+ $ value = -$ type_part ->value ;
58
+ $ type_part = is_int ($ value ) ? new TLiteralInt ($ value ) : new TLiteralFloat ($ value );
55
59
} elseif ($ type_part instanceof TLiteralFloat) {
56
60
$ type_part = new TLiteralFloat (-$ type_part ->value );
57
61
} elseif ($ type_part instanceof TIntRange) {
Original file line number Diff line number Diff line change @@ -1013,6 +1013,15 @@ function toPositiveInt(int $i): int
1013
1013
'$b=== ' => 'non-falsy-string ' ,
1014
1014
],
1015
1015
],
1016
+ 'unaryMinusOverflows ' => [
1017
+ 'code ' => <<<'PHP'
1018
+ <?php
1019
+ $a = -(1 << 63);
1020
+ PHP,
1021
+ 'assertions ' => [
1022
+ '$a=== ' => 'float(9.2233720368548E+18) ' ,
1023
+ ],
1024
+ ],
1016
1025
];
1017
1026
}
1018
1027
You can’t perform that action at this time.
0 commit comments