Repository navigation
Keep the list flag when a list shape is intersected with an array type - #6717
Merged
Merged
Conversation
janedbal
marked this pull request as ready for review
October 9, 2026 11:10
Collaborator
|
This pull request has been marked as ready for review. |
Contributor
|
//cc @SanderMuller |
staabm
requested changes
Oct 14, 2026
staabm
left a comment
Contributor
There was a problem hiding this comment.
needs rebase. otherwise LGTM
staabm
requested review from
VincentLanglet and
ondrejmirtes
and removed request for
ondrejmirtes
October 14, 2026 05:36
There was a problem hiding this comment.
🟢 Approval recommended
The fix is focused, mirrored consistently, and backed by suitable regression coverage.
0 open findings
What changed in this PR
Fixes #15391 by preserving list semantics when intersecting list-shaped constant arrays with array types.
Changes:
- Retains the list flag during intersection rebuilding.
- Mirrors behavior in the Turbo extension.
- Adds regression coverage and updates Turbo compatibility.
| File | Description |
|---|---|
src/Type/TypeCombinator.php |
Preserves list semantics after rebuilding shapes. |
turbo-ext/src/TypeCombinator.cpp |
Mirrors the PHP implementation. |
tests/PHPStan/Analyser/nsrt/bug-15391.php |
Covers narrowing, direct intersection, and loops. |
src/Turbo/TurboExtensionEnabler.php |
Updates the expected Turbo version. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
TypeCombinator::intersect() rebuilds a ConstantArrayType through the
builder when the other side is an ArrayType. The builder marks every
optional key as a possible non-list key, so a list shape with two or more
optional keys became a plain array shape. This happens for example when
in_array() narrows the haystack, and it made a returned list{...} fail
a list<T> return type.
A subset of a list is a list, so the rebuilt shape now keeps the list flag
when the source shape is a list.
…e in turbo-ext Port b3d727229 to the native TypeCombinator. When intersectConstantArrayWith() rebuilds a list shape through the builder, it now intersects the result with AccessoryArrayListType, the same as the PHP twin.
janedbal
force-pushed
the
fix-byref-closure-list
branch
from
October 14, 2026 09:52
ea802c0 to
0c9e5be
Compare
VincentLanglet
approved these changes
Oct 14, 2026
staabm
approved these changes
Oct 14, 2026
Contributor
|
thank you! |
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.
Closes phpstan/phpstan#15391
in_array()narrowing drops the list flag from alist{...}shape that has two or more optional keys. This is a regression in 2.1.41 from 951d9e4 (#5067).TypeCombinator::intersect()rebuilds aConstantArrayTypethroughConstantArrayTypeBuilderwhen the other side is anArrayType. The builder marks each optional key as a possible non-list key, so the rebuilt shape is only "maybe a list".TypeCombinator::intersect()now intersects the rebuilt shape withAccessoryArrayListTypewhen the source shape is a list.turbo-ext/src/TypeCombinator.cppgets the same change.tests/PHPStan/Analyser/nsrt/bug-15391.phpis the regression test. It fails without the change inTypeCombinator.phpand passes with it.— Claude