Skip to content

Fix Array_ expr type resolving with unpacked array items#1586

Merged
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
herndlm:fix-7724
Aug 5, 2022
Merged

Fix Array_ expr type resolving with unpacked array items#1586
ondrejmirtes merged 3 commits intophpstan:1.8.xfrom
herndlm:fix-7724

Conversation

@herndlm
Copy link
Copy Markdown
Contributor

@herndlm herndlm commented Aug 3, 2022

Closes phpstan/phpstan#7724

The problem was the missing $optional arg for the ConstantArrayTypeBuilder::setOffsetValueType for the first conditional handling string keys. Unpacked array item values are always optional in that context as long as the array is not iterable at least once.

UPDATE: One more thing was looking weird to me which I fixed in the second commit. I removed the check of $valueType->getIterableValueType()->isIterableAtLeastOnce() which goes too far if I'm not mistaken. As the iterableValueType does not influence the outer array non-emptyness basically. See the affected test files for bug-5287

@herndlm herndlm marked this pull request as ready for review August 3, 2022 07:35
@herndlm herndlm marked this pull request as draft August 3, 2022 08:00
@herndlm herndlm marked this pull request as ready for review August 3, 2022 08:20
@ondrejmirtes ondrejmirtes merged commit cb46f97 into phpstan:1.8.x Aug 5, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

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.

Array destructuring: Variable always exists and is not falsy.

3 participants