php7: implement array destructuring
commitf3566502c6ac5d5caafc584216d03374ed73ee23
authorFred Emmott <fe@fb.com>
Fri, 6 Apr 2018 16:40:43 +0000 (6 09:40 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Fri, 6 Apr 2018 16:43:01 +0000 (6 09:43 -0700)
treec22ace93dfae12a7ba338681d0e2feb6b5215e09
parent93131086001beea4240891690b8ea07d2c10a3aa
php7: implement array destructuring

Summary:
Goal is to allow `[$a, [$b, $c]] = [1, [2, 3]]`. This is done by:

- making `list()` an array literal
- allow assigning to array literals
- when we attempt to assign to an array literal, validate that it's a valid LHS
- allow any number of commas at any point in the literal in the parser as `[,,$three,,] = [1,2,3,4,5]` is valid
- in the emitter, raise a fatal if we have any empty values on an RHS, and ignore a single trailing comma

Making `[$a, $b]` a valid assignment_list isn't practical as that makes the
grammar ambiguous.

Not supported in HackC or the typechecker; that doesn't seem practical with the
3.25 timeline.

fixes facebook/hhvm#7535

Differential Revision: D7057672

fbshipit-source-id: 2447406b4665d0ab1930036517fe17601a23b1b3
21 files changed:
hphp/compiler/analysis/emitter.cpp
hphp/compiler/expression/array_pair_expression.cpp
hphp/compiler/expression/expression_list.h
hphp/compiler/parser/parser.cpp
hphp/compiler/parser/parser.h
hphp/hhvm/process-init.cpp
hphp/parser/hphp.5.tab.cpp [copied from hphp/parser/hphp.7.tab.cpp with 62% similarity]
hphp/parser/hphp.7.tab.cpp [copied from hphp/parser/hphp.5.tab.cpp with 60% similarity]
hphp/parser/hphp.y
hphp/runtime/ext/factparse/parser.cpp
hphp/runtime/ext/factparse/parser.h
hphp/test/ext/test_parser_expr.cpp
hphp/test/hackc_failing_tests_slow
hphp/test/hackc_repo_failing_tests_slow
hphp/test/hhcodegen_failing_tests_slow
hphp/test/slow/php7_backported/array_destructuring.php [new file with mode: 0644]
hphp/test/slow/php7_backported/array_destructuring.php.expect [new file with mode: 0644]
hphp/test/slow/php7_backported/array_destructuring.php.ini [new file with mode: 0644]
hphp/test/slow/php7_backported/array_destructuring_byref.php [new file with mode: 0644]
hphp/test/slow/php7_backported/array_destructuring_byref.php.expectf [new file with mode: 0644]
hphp/test/slow/php7_backported/array_destructuring_byref.php.ini [new file with mode: 0644]