Skip to content

Fix incorrect narrowing of nested array after assignment#5258

Merged
staabm merged 13 commits intophpstan:2.1.xfrom
staabm:arr-miss
Mar 20, 2026
Merged

Fix incorrect narrowing of nested array after assignment#5258
staabm merged 13 commits intophpstan:2.1.xfrom
staabm:arr-miss

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Mar 20, 2026

@staabm staabm marked this pull request as ready for review March 20, 2026 16:03
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm requested a review from VincentLanglet March 20, 2026 16:15
@VincentLanglet
Copy link
Contributor

The condition

if ($i === 0) {
					$unionValues = true;
				} elseif (
					$overwritesExistingOffset === true
					&& $i === count($offsetTypes) - 1
					&&
						(
							$originalValueToWrite->isConstantScalarValue()->yes()
							|| !$offsetValueType->getIterableValueType()->isSuperTypeOf($valueToWrite)->yes()
						)
				) {
					$unionValues = true;
				}

is unclear to me @staabm I feel like a comment would be nice ; do you want to write one (since you worked on the PR) or let the bot generate one ?

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

The renaming makes the code clearer to me

@staabm
Copy link
Contributor Author

staabm commented Mar 20, 2026

I am 100% sure there is a better way to fix this.. but I spent already days on this (and related phpstan-bot PRs).
I will try to generalize and improve the logic in a future PR, but will merge it now as it still improves the status-quo

@staabm staabm merged commit ec82e22 into phpstan:2.1.x Mar 20, 2026
649 of 651 checks passed
@staabm staabm deleted the arr-miss branch March 20, 2026 17: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.

3 participants