From 051c4a45fd831662c07c74ebcb97f0f4bbfffba0 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 10 Jun 2026 14:46:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(parser):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=B5=8C=E5=A5=97=20list()=20=E8=A7=A3=E6=9E=84=E8=B5=8B?= =?UTF-8?q?=E5=80=BC=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 AssignOpTrait 中实现嵌套列表解构逻辑 - 添加临时变量生成用于处理嵌套数组 - 集成 parseAssignToList 方法处理嵌套 list 结构 - 保持原有非嵌套情况下的行为不变 - 添加完整的嵌套 list 解构功能测试用例 - 确保多层嵌套的列表解构能够正确执行 --- src/Php/Parser/AssignOpTrait.php | 21 +++++++++++++------- tests/aot/arrays/list-nested.phpt | 32 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 tests/aot/arrays/list-nested.phpt diff --git a/src/Php/Parser/AssignOpTrait.php b/src/Php/Parser/AssignOpTrait.php index a6de8cb4..b3aae194 100644 --- a/src/Php/Parser/AssignOpTrait.php +++ b/src/Php/Parser/AssignOpTrait.php @@ -109,14 +109,21 @@ trait AssignOpTrait continue; } if ($item instanceof ArrayItem) { - $oriInAssignExpr = $this->context->inAssignExpr; - $this->context->inAssignExpr = true; - $var = $this->parseIdentifier($item->value); - $this->context->inAssignExpr = $oriInAssignExpr; - if ($this->isVarExpr($item->value) and !$this->hasVar($var)) { - $this->addLocalVar($var, self::TYPE_VAR); + if ($item->value instanceof Expr\List_) { + $nestedTmp = $this->genTmpVarName(); + $this->addLocalVar($nestedTmp, self::TYPE_ARRAY); + $code .= "{$nestedTmp} = {$tmpVar}.item({$k}); "; + $code .= $this->parseAssignToList($item->value, new Variable($nestedTmp)); + } else { + $oriInAssignExpr = $this->context->inAssignExpr; + $this->context->inAssignExpr = true; + $var = $this->parseIdentifier($item->value); + $this->context->inAssignExpr = $oriInAssignExpr; + if ($this->isVarExpr($item->value) and !$this->hasVar($var)) { + $this->addLocalVar($var, self::TYPE_VAR); + } + $code .= "{$var} = {$tmpVar}.item({$k}); "; } - $code .= "{$var} = {$tmpVar}.item({$k}); "; } else { abort($item); } diff --git a/tests/aot/arrays/list-nested.phpt b/tests/aot/arrays/list-nested.phpt new file mode 100644 index 00000000..1b1fefe6 --- /dev/null +++ b/tests/aot/arrays/list-nested.phpt @@ -0,0 +1,32 @@ +--TEST-- +nested list() destructuring +--FILE-- + +--EXPECT-- +1 +2 +3 +4 +10 +20 +30 +40 +50