File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 124124use function get_class ;
125125use function in_array ;
126126use function is_float ;
127+ use function is_int ;
127128use function is_string ;
128129use function ltrim ;
129130use function max ;
@@ -1060,7 +1061,12 @@ private function resolveType(Expr $node): Type
10601061 $ newTypes = [];
10611062 foreach ($ scalarValues as $ scalarValue ) {
10621063 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 );
10641070 } elseif ($ scalarValue instanceof ConstantFloatType) {
10651071 $ newTypes [] = new ConstantFloatType (-$ scalarValue ->getValue ());
10661072 }
Original file line number Diff line number Diff line change @@ -641,6 +641,12 @@ public function testBug4308(): void
641641 $ this ->assertNoErrors ($ errors );
642642 }
643643
644+ public function testBug6979 (): void
645+ {
646+ $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-6979.php ' );
647+ $ this ->assertNoErrors ($ errors );
648+ }
649+
644650 /**
645651 * @param string[]|null $allAnalysedFiles
646652 * @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