Call operator type specifying extensions for bitwise and arithmetic operators#5226
Merged
VincentLanglet merged 2 commits intophpstan:2.1.xfrom Mar 19, 2026
Merged
Conversation
4 tasks
Contributor
Author
|
I believe the two failing tests are unrelated to this change based on other PRs I'm seeing and their associated error messages. |
VincentLanglet
approved these changes
Mar 17, 2026
staabm
reviewed
Mar 18, 2026
Contributor
Author
|
I can get some extra tests added for bit-shifting. @staabm & @ondrejmirtes Just to make sure I'm following your comments correctly, should the logic in InitializerExprTypeResolver stay as-is? Sounds like changing method visibility per the original suggestion is out. |
Contributor
|
Leave the visibility as is , right |
staabm
approved these changes
Mar 18, 2026
…perators - Add extension calls to getBitwiseAndType, getBitwiseOrType, getBitwiseXorType - Move extension call to top of resolveCommonMath (before integer range optimization) - Remove duplicate extension call later in resolveCommonMath - Add TestBitwiseOperatorTypeSpecifyingExtension for testing bitwise extension calls - Add OperatorTypeSpecifyingExtensionTypeInferenceTest with tests for both bitwise (TestBitwiseOperand) and arithmetic (TestDecimal) operators This ensures operator type specifying extensions are called consistently for all supported operators, allowing custom types to specify operator return types. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
79d3b9e to
027f16d
Compare
Contributor
|
I think we can merge this, since ondrej only request is respected. He will still be able to review this before the release. |
Contributor
Contributor
Author
|
Sounds great! I'm not sure if I can get to it tomorrow but hopefully fairly soon if not. TY for the feedback on everything. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR ensures
OperatorTypeSpecifyingExtensionimplementations are called consistently for all supported binary operators:getBitwiseAndType,getBitwiseOrType,getBitwiseXorTyperesolveCommonMath(before integer range optimization)resolveCommonMathThis is prerequisite work for phpstan/phpstan#14288 (GMP operator type inference), split out per review feedback on #5223.
Testing approach
Per @ondrejmirtes' feedback:
This PR creates synthetic test extensions independent of any specific type (like GMP):
TestBitwiseOperand- A dummy fixture classTestBitwiseOperatorTypeSpecifyingExtension- ReturnsTestBitwiseOperandfor&,|,^operatorsTestDecimal+TestDecimalOperatorTypeSpecifyingExtensionfor arithmetic operatorsThe test verifies the resolver correctly invokes extensions for both bitwise and arithmetic operators. This ensures the resolver infrastructure remains tested even if specific extensions (like a future GMP extension) are removed.
Test plan
OperatorTypeSpecifyingExtensionTypeInferenceTestwith 8 assertionsGenerated with Claude Code