Skip to content

Commit 79d3b9e

Browse files
Firehedclaude
andcommitted
Add extension calls for shift left/right operators
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 80e6de9 commit 79d3b9e

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,12 @@ public function getShiftLeftType(Expr $left, Expr $right, callable $getTypeCallb
17741774
$leftType = $getTypeCallback($left);
17751775
$rightType = $getTypeCallback($right);
17761776

1777+
$specifiedTypes = $this->operatorTypeSpecifyingExtensionRegistryProvider->getRegistry()
1778+
->callOperatorTypeSpecifyingExtensions(new BinaryOp\ShiftLeft($left, $right), $leftType, $rightType);
1779+
if ($specifiedTypes !== null) {
1780+
return $specifiedTypes;
1781+
}
1782+
17771783
return $this->getShiftLeftTypeFromTypes($left, $right, $leftType, $rightType);
17781784
}
17791785

@@ -1838,6 +1844,12 @@ public function getShiftRightType(Expr $left, Expr $right, callable $getTypeCall
18381844
$leftType = $getTypeCallback($left);
18391845
$rightType = $getTypeCallback($right);
18401846

1847+
$specifiedTypes = $this->operatorTypeSpecifyingExtensionRegistryProvider->getRegistry()
1848+
->callOperatorTypeSpecifyingExtensions(new BinaryOp\ShiftRight($left, $right), $leftType, $rightType);
1849+
if ($specifiedTypes !== null) {
1850+
return $specifiedTypes;
1851+
}
1852+
18411853
return $this->getShiftRightTypeFromTypes($left, $right, $leftType, $rightType);
18421854
}
18431855

tests/PHPStan/Analyser/data/operator-type-specifying-extension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ function testBitwiseXor(TestBitwiseOperand $a, TestBitwiseOperand $b): void
2525
assertType('PHPStan\Fixture\TestBitwiseOperand', $a ^ $b);
2626
}
2727

28+
function testShiftLeft(TestBitwiseOperand $a, TestBitwiseOperand $b): void
29+
{
30+
assertType('PHPStan\Fixture\TestBitwiseOperand', $a << $b);
31+
}
32+
33+
function testShiftRight(TestBitwiseOperand $a, TestBitwiseOperand $b): void
34+
{
35+
assertType('PHPStan\Fixture\TestBitwiseOperand', $a >> $b);
36+
}
37+
2838
// =============================================================================
2939
// Arithmetic operator extension tests (via TestDecimal)
3040
// =============================================================================

tests/PHPStan/Type/TestBitwiseOperatorTypeSpecifyingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function isOperatorSupported(string $operatorSigil, Type $leftSide, Type
1515
{
1616
$testType = new ObjectType(TestBitwiseOperand::class);
1717

18-
return in_array($operatorSigil, ['&', '|', '^'], true)
18+
return in_array($operatorSigil, ['&', '|', '^', '<<', '>>'], true)
1919
&& $testType->isSuperTypeOf($leftSide)->yes()
2020
&& $testType->isSuperTypeOf($rightSide)->yes();
2121
}

0 commit comments

Comments
 (0)