Preserve surviving offsets when popping or shifting a list - #6274
Merged
Merged
Conversation
staabm
reviewed
Aug 26, 2026
| $members[] = $type; | ||
| continue; | ||
| } | ||
| if ($type instanceof HasOffsetValueType || $type instanceof HasOffsetType) { |
Contributor
There was a problem hiding this comment.
I think we need a nsrt test for a list which contains a mix of string and int offset-types
hasOffsetValue(n, T) on a list proves indices 0..n exist, so popping the highest index keeps hasOffset(0..n-1) - previously the accessory answered with no opinion and the whole intersection degraded to a possibly-empty list, so a second array_pop() in the same statement typed as nullable. Shifting reindexes, so the value known at n moves to n - 1 intact. TemplateType members pass through unchanged, as in intersectTypesPreserveTemplateType().
ondrejmirtes
force-pushed
the
list-pop-shift-offsets
branch
from
August 26, 2026 11:49
b6633b0 to
5ee6f45
Compare
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.
Extracted from
resolve-type-rewrite-2(first of the tier-1/tier-2 extraction series).When popping or shifting a list carrying
hasOffsetValue(n, T)/hasOffset(n)accessory types, the surviving offsets were dropped entirely, so a subsequentarray_pop()/array_shift()degraded toT|nulleven though the list provably still had elements:n − 1survive ashasOffset(their values are unknown — the value known atnmay have been the popped one).n's entry moves ton − 1, preservinghasOffsetValue.Verified red before the fix: without the
IntersectionTypechange, the new nsrt fixture fails withstring|nullwherestringis expected afterarray_pop()on a count-narrowedexplode()result.Gates: full suite 21155 tests / 96002 assertions green,
make phpstanclean,make csclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01R7pqAkCx4xP6WYxBo2nMJE