Skip to content

Commit 4442956

Browse files
Firehedclaude
andcommitted
Add GMP support for unary minus and bitwise NOT operators
These unary operators are not covered by the OperatorTypeSpecifyingExtension interface (which handles binary operators only), so they need direct handling in InitializerExprTypeResolver. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 771a7ad commit 4442956

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,11 @@ public function getUnaryMinusType(Expr $expr, callable $getTypeCallback): Type
26112611
{
26122612
$type = $getTypeCallback($expr);
26132613

2614+
// GMP supports unary minus and returns GMP
2615+
if ($type->isObject()->yes() && (new ObjectType('GMP'))->isSuperTypeOf($type)->yes()) {
2616+
return new ObjectType('GMP');
2617+
}
2618+
26142619
$type = $this->getUnaryMinusTypeFromType($expr, $type);
26152620
if ($type instanceof IntegerRangeType) {
26162621
return $getTypeCallback(new Expr\BinaryOp\Mul($expr, new Int_(-1)));
@@ -2652,6 +2657,11 @@ public function getBitwiseNotType(Expr $expr, callable $getTypeCallback): Type
26522657
{
26532658
$exprType = $getTypeCallback($expr);
26542659

2660+
// GMP supports bitwise not and returns GMP
2661+
if ($exprType->isObject()->yes() && (new ObjectType('GMP'))->isSuperTypeOf($exprType)->yes()) {
2662+
return new ObjectType('GMP');
2663+
}
2664+
26552665
return $this->getBitwiseNotTypeFromType($exprType);
26562666
}
26572667

0 commit comments

Comments
 (0)