65
65
use PHPStan \Type \TypeUtils ;
66
66
use PHPStan \Type \TypeWithClassName ;
67
67
use PHPStan \Type \UnionType ;
68
+ use PHPStan \Type \VerbosityLevel ;
69
+
68
70
use function array_keys ;
69
71
use function array_merge ;
70
72
use function assert ;
@@ -1479,7 +1481,7 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
1479
1481
return $ union ->toNumber ();
1480
1482
}
1481
1483
1482
- return $ this ->integerRangeMath ($ leftType , $ expr , $ rightType );
1484
+ return $ this ->integerRangeMath ($ leftNumberType , $ expr , $ rightNumberType );
1483
1485
}
1484
1486
1485
1487
$ specifiedTypes = $ this ->callOperatorTypeSpecifyingExtensions ($ expr , $ leftType , $ rightType );
@@ -1532,7 +1534,6 @@ private function resolveCommonMath(Expr\BinaryOp $expr, Type $leftType, Type $ri
1532
1534
/**
1533
1535
* @param ConstantIntegerType|IntegerRangeType $range
1534
1536
* @param BinaryOp\Div|BinaryOp\Minus|BinaryOp\Mul|BinaryOp\Plus $node
1535
- * @param IntegerRangeType|ConstantIntegerType|UnionType $operand
1536
1537
*/
1537
1538
private function integerRangeMath (Type $ range , BinaryOp $ node , Type $ operand ): Type
1538
1539
{
@@ -1549,8 +1550,9 @@ private function integerRangeMath(Type $range, BinaryOp $node, Type $operand): T
1549
1550
$ unionParts = [];
1550
1551
1551
1552
foreach ($ operand ->getTypes () as $ type ) {
1552
- if ($ type instanceof IntegerRangeType || $ type instanceof ConstantIntegerType) {
1553
- $ unionParts [] = $ this ->integerRangeMath ($ range , $ node , $ type );
1553
+ $ numberType = $ type ->toNumber ();
1554
+ if ($ numberType instanceof IntegerRangeType || $ numberType instanceof ConstantIntegerType) {
1555
+ $ unionParts [] = $ this ->integerRangeMath ($ range , $ node , $ numberType );
1554
1556
} else {
1555
1557
$ unionParts [] = $ type ->toNumber ();
1556
1558
}
@@ -1564,6 +1566,11 @@ private function integerRangeMath(Type $range, BinaryOp $node, Type $operand): T
1564
1566
return $ union ->toNumber ();
1565
1567
}
1566
1568
1569
+ $ operand = $ operand ->toNumber ();
1570
+ if (!$ operand instanceof IntegerRangeType && !$ operand instanceof ConstantIntegerType) {
1571
+ return $ operand ;
1572
+ }
1573
+
1567
1574
if ($ operand instanceof IntegerRangeType) {
1568
1575
$ operandMin = $ operand ->getMin ();
1569
1576
$ operandMax = $ operand ->getMax ();
0 commit comments