File tree 3 files changed +22
-1
lines changed
3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 124
124
use function get_class ;
125
125
use function in_array ;
126
126
use function is_float ;
127
+ use function is_int ;
127
128
use function is_string ;
128
129
use function ltrim ;
129
130
use function max ;
@@ -1060,7 +1061,12 @@ private function resolveType(Expr $node): Type
1060
1061
$ newTypes = [];
1061
1062
foreach ($ scalarValues as $ scalarValue ) {
1062
1063
if ($ scalarValue instanceof ConstantIntegerType) {
1063
- $ newTypes [] = new ConstantIntegerType (-$ scalarValue ->getValue ());
1064
+ /** @var int|float $newValue */
1065
+ $ newValue = -$ scalarValue ->getValue ();
1066
+ if (!is_int ($ newValue )) {
1067
+ return $ type ;
1068
+ }
1069
+ $ newTypes [] = new ConstantIntegerType ($ newValue );
1064
1070
} elseif ($ scalarValue instanceof ConstantFloatType) {
1065
1071
$ newTypes [] = new ConstantFloatType (-$ scalarValue ->getValue ());
1066
1072
}
Original file line number Diff line number Diff line change @@ -641,6 +641,12 @@ public function testBug4308(): void
641
641
$ this ->assertNoErrors ($ errors );
642
642
}
643
643
644
+ public function testBug6979 (): void
645
+ {
646
+ $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-6979.php ' );
647
+ $ this ->assertNoErrors ($ errors );
648
+ }
649
+
644
650
/**
645
651
* @param string[]|null $allAnalysedFiles
646
652
* @return Error[]
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace Bug6979 ;
4
+
5
+ foreach ([PHP_INT_MIN , 0 , PHP_INT_MAX ] as $ v ) {
6
+ if ($ v !== PHP_INT_MIN ) {
7
+ $ invalidNumbers [] = -$ v ;
8
+ }
9
+ }
You can’t perform that action at this time.
0 commit comments