Skip to content

Language: keyed list destructuring with spread — ['k' => $v, ...$tail] = (zend_compile.c) #4889

Description

@PurHur

Category

language

Problem

Numeric list spread [$a, ...$rest] = $arr is VM-complete (#4835). Keyed list destructuring with a spread arm — e.g. ['label' => $label, ...$others] = $assoc — is not covered by compliance tests and may use the wrong tail offset: php-cfg spread lowering uses listSpreadFromIndex counting only positional slots, while Zend merges remaining elements after consuming keyed assignments.

Workers should not assume keyed+spread works because numeric spread PHPT passes.

php-src reference

Repro

<?php
$src = ['label' => 'L', 'a' => 1, 'b' => 2];
['label' => $label, ...$rest] = $src;
ksort($rest);
var_export($label);
echo "\n";
var_export($rest);
php repro_keyed_list_spread.php
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro_keyed_list_spread.php'

Record Zend output as authoritative; today VM may assign wrong keys into $rest or fail compile.

Stretch: string-key spread tail must still error when remainder is not a list (same as #4835).

Scope

Area Files
php-cfg patch script/apply-patches.sh — parseListAssignment spread index for keyed arms
Compiler lib/Compiler.php — TYPE_LIST_SPREAD_ASSIGN offset semantics
VM lib/VM.php — merge keyed slots then append list tail
Tests test/compliance/cases/language/list_destructuring_keyed_spread.phpt
JIT Follow #4885 after VM green

Done when

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions