Introduce UnaryOperatorTypeSpecifyingExtension interface#5284
Open
Firehed wants to merge 1 commit intophpstan:2.1.xfrom
Open
Introduce UnaryOperatorTypeSpecifyingExtension interface#5284Firehed wants to merge 1 commit intophpstan:2.1.xfrom
Firehed wants to merge 1 commit intophpstan:2.1.xfrom
Conversation
This adds an extension point for unary operators (-, +, ~), similar to the existing OperatorTypeSpecifyingExtension for binary operators. New types: - UnaryOperatorTypeSpecifyingExtension interface - UnaryOperatorTypeSpecifyingExtensionRegistry - UnaryOperatorTypeSpecifyingExtensionRegistryProvider interface - LazyUnaryOperatorTypeSpecifyingExtensionRegistryProvider implementation Integration: - Hook into InitializerExprTypeResolver for getUnaryPlusType, getUnaryMinusType, getBitwiseNotType - Update UnaryPlusHandler to use InitializerExprTypeResolver (like UnaryMinusHandler) - Add service tag: phpstan.broker.unaryOperatorTypeSpecifyingExtension Testing: - TestUnaryOperand fixture class - TestUnaryOperatorTypeSpecifyingExtension synthetic extension - UnaryOperatorTypeSpecifyingExtensionTypeInferenceTest This enables extensions like GMP to specify return types for unary operators. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4 tasks
VincentLanglet
approved these changes
Mar 23, 2026
Contributor
|
@Firehed There is just the lint build to fix. And since this is a new API, I prefer to get the approval from @ondrejmirtes too. |
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
UnaryOperatorTypeSpecifyingExtensioninterface as the unary operator counterpart to the existingOperatorTypeSpecifyingExtensionfor binary operators-,+, and~operatorsInitializerExprTypeResolverto call registered extensions before falling back to built-in type resolutionThis PR extracts the infrastructure portion from #5223 to allow the API to be reviewed and merged independently before the GMP extension that uses it.
Test plan
UnaryOperatorTypeSpecifyingExtensionTypeInferenceTestwith a synthetic test extension-,+,~) call extensions correctly🤖 Generated with Claude Code