From f42bbc2403ebc1178d9ae4f1029c0e8ddc6aa451 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 30 Nov 2018 11:00:48 +0100 Subject: [PATCH] Avoid default action for error production error is not necessarily going to have a semantic value, make sure that the default action $$=$1 is not used. Fixes #551. --- grammar/php7.y | 1 + lib/PhpParser/Parser/Php7.php | 2 +- test/code/parser/errorHandling/recovery.test | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/grammar/php7.y b/grammar/php7.y index 7705113..681fda0 100644 --- a/grammar/php7.y +++ b/grammar/php7.y @@ -959,6 +959,7 @@ array_pair_list: comma_or_error: ',' | error + { /* do nothing -- prevent default action of $$=$1. See #551. */ } ; inner_array_pair_list: diff --git a/lib/PhpParser/Parser/Php7.php b/lib/PhpParser/Parser/Php7.php index a28a2c4..b34ee82 100644 --- a/lib/PhpParser/Parser/Php7.php +++ b/lib/PhpParser/Parser/Php7.php @@ -2361,7 +2361,7 @@ class Php7 extends \PhpParser\ParserAbstract $this->semValue = $this->semStack[$stackPos]; }, 498 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; + /* do nothing -- prevent default action of $$=$this->semStack[$1]. See $551. */ }, 499 => function ($stackPos) { $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; diff --git a/test/code/parser/errorHandling/recovery.test b/test/code/parser/errorHandling/recovery.test index ae3518d..fdb5ed2 100644 --- a/test/code/parser/errorHandling/recovery.test +++ b/test/code/parser/errorHandling/recovery.test @@ -1400,4 +1400,10 @@ array( ) ) ) -) \ No newline at end of file +) +----- +