Don't drop class statements before error (#952)

When encountering a null statement (indicating that an error occurred),
retain the preceding statements. These were accidentally dropped
previously.

(cherry picked from commit 54103d838734be0499172026525e38cbf6af2711)
This commit is contained in:
xjaja 2023-10-04 05:00:18 +08:00 committed by Nikita Popov
parent 481fec47f4
commit 8d50e9d066
4 changed files with 19 additions and 4 deletions

View File

@ -816,7 +816,7 @@ static_var:
;
class_statement_list_ex:
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } }
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } else { $$ = $1; } }
| /* empty */ { init(); }
;

View File

@ -1935,7 +1935,7 @@ class Php7 extends \PhpParser\ParserAbstract
$this->semValue = new Node\StaticVar($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(3-1)], $this->tokenEndStack[$stackPos]));
},
340 => function ($stackPos) {
if ($this->semStack[$stackPos-(2-2)] !== null) { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; }
if ($this->semStack[$stackPos-(2-2)] !== null) { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; } else { $this->semValue = $this->semStack[$stackPos-(2-1)]; }
},
341 => function ($stackPos) {
$this->semValue = array();

View File

@ -1953,7 +1953,7 @@ class Php8 extends \PhpParser\ParserAbstract
$this->semValue = new Node\StaticVar($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(3-1)], $this->tokenEndStack[$stackPos]));
},
340 => function ($stackPos) {
if ($this->semStack[$stackPos-(2-2)] !== null) { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; }
if ($this->semStack[$stackPos-(2-2)] !== null) { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; } else { $this->semValue = $this->semStack[$stackPos-(2-1)]; }
},
341 => function ($stackPos) {
$this->semValue = array();

View File

@ -838,11 +838,12 @@ array(
<?php
class Foo {
public $bar1;
publi $foo;
public $bar;
}
-----
Syntax error, unexpected T_STRING from 4:5 to 4:9
Syntax error, unexpected T_STRING from 5:5 to 5:9
array(
0: Stmt_Class(
attrGroups: array(
@ -856,6 +857,20 @@ array(
)
stmts: array(
0: Stmt_Property(
attrGroups: array(
)
flags: PUBLIC (1)
type: null
props: array(
0: PropertyItem(
name: VarLikeIdentifier(
name: bar1
)
default: null
)
)
)
1: Stmt_Property(
attrGroups: array(
)
flags: PUBLIC (1)