Skip to content

fix(types): list destructuring accepts a union/assoc RHS carrying an array member#522

Open
chadmandoo wants to merge 1 commit into
illegalstudio:mainfrom
chadmandoo:upstream-pr/list-unpack-union-rhs
Open

fix(types): list destructuring accepts a union/assoc RHS carrying an array member#522
chadmandoo wants to merge 1 commit into
illegalstudio:mainfrom
chadmandoo:upstream-pr/list-unpack-union-rhs

Conversation

@chadmandoo

Copy link
Copy Markdown
Contributor

What

list() / [$a, $b] = ... destructuring only accepted a plain Array(T) right-hand side and errored otherwise. A common pattern was rejected:

private function mk(int $n): ?array { /* ... */ }

$entry = $this->mk($n);
if ($entry === null) { continue; }
[$key, $value] = $entry;   // $entry types as Union[Array, Void] here

How

In check_list_unpack, accept an AssocArray RHS and a Union that carries an array-like member (Array / AssocArray / Mixed) — both are arrays at runtime in well-typed code. Their elements bind as Mixed (adaptive access), the trust posture PHP applies at runtime.

Test

test_list_unpack_null_narrowed_array_return — destructuring a null-narrowed ?array return in a loop, byte-parity vs PHP 8.5.

🤖 Generated with Claude Code

…array member

`list()` / `[$a, $b] = ...` destructuring only accepted a plain `Array(T)` RHS
and errored on everything else. A `?array` method return narrowed by `=== null`
still types as `Union[Array, Void]` at the destructure (and an associative-array
or Mixed union is an array at runtime in well-typed code). Accept an
`AssocArray` RHS and a union that carries an array-like member; their elements
bind as Mixed (adaptive access), the trust posture PHP applies at runtime.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant