Fix parsing of postfix operators.
commitb52219069724f6e47a8c70702369c9af1a147823
authorJez Ng <jezng@fb.com>
Wed, 8 Oct 2014 20:14:53 +0000 (8 13:14 -0700)
committerhhvm-bot <hhvm-bot@fb.com>
Wed, 8 Oct 2014 20:30:28 +0000 (8 13:30 -0700)
tree7e8beb2170796cbc21fb3a776778cfaa4e661206
parentc71d929a3452417e91baab92f70c7fc5e1ddfaad
Fix parsing of postfix operators.

Summary: Based on what I understand of the parser's reduce code, this should be the
right way to parse things...

It might look like expr_postfix_unary is completely disregarding precedence,
but that's because the functions calling it handle precedence already.

In `$a->b++`, reduce() 'shifts' `$a->b` onto the stack, finds out that `++` has
lower precedence than `->`, then returns. So expr_postfix_unary gets called with e1
set to `$a->b`.

In `$a && $b++`, when parsing $b, reduce() sees that `++` has higher precedence
than `&&` and so creates `$b++`.

Finally, the precedence of a postfix operator should not affect the remainder
of the parse. I.e. we should parse `$a && $b++ === $c` as `$a && ($b++ === $c)`
rather than `($a && $b++) === $c` -- even though `++` has higher precedence
than both `&&` and `===`, we decide to shift `===` based on the relative
precedence of `&&` and `===`, and `++` does not come into the picture.

Reviewed By: @pikatchu

Differential Revision: D1598832
hphp/hack/src/parsing/parser_hack.ml
hphp/hack/test/typecheck/postfix_parse.php [new file with mode: 0644]
hphp/hack/test/typecheck/postfix_parse.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/postfix_parse2.php [new file with mode: 0644]
hphp/hack/test/typecheck/postfix_parse2.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/postfix_parse3.php [new file with mode: 0644]
hphp/hack/test/typecheck/postfix_parse3.php.exp [new file with mode: 0644]