Skip to content

Update RangeFunctionReturnTypeExtension to include known integer ranges for keys - #4251

Open
PrinsFrank wants to merge 1 commit into
phpstan:2.3.xfrom
PrinsFrank:range-returns-list-with-known-nr-of-elements
Open

PrinsFrank wants to merge 1 commit into
phpstan:2.3.xfrom
PrinsFrank:range-returns-list-with-known-nr-of-elements

Conversation

@PrinsFrank

Copy link
Copy Markdown
Contributor

Right now, the range function returns a list Type for large numbers. we can narrow this down, because we do actually know the upper and lower bounds of the keys, by subtracting the lower bound from the upper bound and dividing that by the step number.

I think this covers all scenarios, let me know if I've missed anything!

@PrinsFrank
PrinsFrank force-pushed the range-returns-list-with-known-nr-of-elements branch from 783dac8 to 884429f Compare August 20, 2025 19:32
@staabm

staabm commented Aug 21, 2025 •

Copy link
Copy Markdown
Contributor

Misses a type-inference test which fails without the patch using assertType

@staabm

staabm commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

@PrinsFrank please rebase and add a test

@ondrejmirtes
ondrejmirtes force-pushed the range-returns-list-with-known-nr-of-elements branch from 884429f to 30d2218 Compare October 31, 2026 13:24
@ondrejmirtes
ondrejmirtes changed the base branch from 2.1.x to 2.3.x October 31, 2026 13:24
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.

2 participants