Skip to content

Commit

Permalink
Wrap List_ in ArrayItem
Browse files Browse the repository at this point in the history
This was correctly done for the 'key'=>list() form, but not for
unkeyed nested lists.
  • Loading branch information
nikic committed Dec 1, 2016
1 parent 68973ae commit 3e158a2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion grammar/php5.y
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ list_expr_elements:

list_expr_element:
variable { $$ = Expr\ArrayItem[$1, null, false]; }
| list_expr { $$ = $1; }
| list_expr { $$ = Expr\ArrayItem[$1, null, false]; }
| /* empty */ { $$ = null; }
;

Expand Down
2 changes: 1 addition & 1 deletion grammar/php7.y
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ list_expr_elements:

list_expr_element:
variable { $$ = Expr\ArrayItem[$1, null, false]; }
| list_expr { $$ = $1; }
| list_expr { $$ = Expr\ArrayItem[$1, null, false]; }
| expr T_DOUBLE_ARROW variable { $$ = Expr\ArrayItem[$3, $1, false]; }
| expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; }
| /* empty */ { $$ = null; }
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Parser/Php5.php
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,7 @@ protected function reduceRule522() {
}

protected function reduceRule523() {
$this->semValue = $this->semStack[$this->stackPos-(1-1)];
$this->semValue = new Expr\ArrayItem($this->semStack[$this->stackPos-(1-1)], null, false, $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes);
}

protected function reduceRule524() {
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Parser/Php7.php
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ protected function reduceRule459() {
}

protected function reduceRule460() {
$this->semValue = $this->semStack[$this->stackPos-(1-1)];
$this->semValue = new Expr\ArrayItem($this->semStack[$this->stackPos-(1-1)], null, false, $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes);
}

protected function reduceRule461() {
Expand Down
20 changes: 12 additions & 8 deletions test/code/parser/expr/assign.test
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,21 @@ array(
)
byRef: false
)
1: Expr_List(
items: array(
0: null
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: c
1: Expr_ArrayItem(
key: null
value: Expr_List(
items: array(
0: null
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: c
)
byRef: false
)
byRef: false
)
)
byRef: false
)
2: Expr_ArrayItem(
key: null
Expand Down

0 comments on commit 3e158a2

Please sign in to comment.