Skip to content

Support int range in bitwise operations#4435

Merged
VincentLanglet merged 5 commits intophpstan:2.1.xfrom
VincentLanglet:bitwiseRange
Feb 8, 2026
Merged

Support int range in bitwise operations#4435
VincentLanglet merged 5 commits intophpstan:2.1.xfrom
VincentLanglet:bitwiseRange

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 13, 2025

@VincentLanglet
Copy link
Contributor Author

Seems like it solves phpstan/phpstan#9384 too, I need to add regression tests

@VincentLanglet
Copy link
Contributor Author

#4437 first would be great

@ondrejmirtes
Copy link
Member

#4437 now merged.

@VincentLanglet VincentLanglet marked this pull request as ready for review February 7, 2026 12:43
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@VincentLanglet VincentLanglet marked this pull request as draft February 7, 2026 12:44
@VincentLanglet VincentLanglet force-pushed the bitwiseRange branch 3 times, most recently from 18de880 to ccafa7b Compare February 7, 2026 15:24
@VincentLanglet VincentLanglet marked this pull request as ready for review February 7, 2026 18:28
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@VincentLanglet VincentLanglet requested a review from staabm February 7, 2026 18:28
Copy link
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future we might move the finite/constant-types logic into a new PHPStan\Type\TypeUtils method

		if ($leftType instanceof IntegerRangeType) {
			$leftTypes = $leftType->getFiniteTypes();
		} else {
			$leftTypes = $leftType->getConstantScalarTypes();
		}

but this is an idea for a followup PR

@staabm
Copy link
Contributor

staabm commented Feb 7, 2026

in a followup we could add similar logic to other operator methods InitializerExprTypeResolver which atm only call getConstantScalarTypes but not getFiniteTypes.

@VincentLanglet
Copy link
Contributor Author

in a followup we could add similar logic to other operator methods InitializerExprTypeResolver which atm only call getConstantScalarTypes but not getFiniteTypes.

Which operator you have in mind ? For common maths, they end up in integerRangeMath

@staabm
Copy link
Contributor

staabm commented Feb 8, 2026

Which operator you have in mind ?

spaceship, mod

Copy link
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

@VincentLanglet VincentLanglet merged commit e85dc34 into phpstan:2.1.x Feb 8, 2026
633 of 639 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

int-mask-of does not work well with operations on the int mask Bitwise Operators & restricted integers & properties -> Error that shouldn't be

4 participants