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>
@chadmandoo chadmandoo force-pushed the upstream-pr/list-unpack-union-rhs branch from 4a3375d to 23ab06d Compare July 11, 2026 14:18
@github-actions github-actions Bot added area:types Touches type checking, inference, or compatibility. size:xs Very small pull request. type:fix Corrects broken or incompatible behavior. labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:types Touches type checking, inference, or compatibility. size:xs Very small pull request. type:fix Corrects broken or incompatible behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant