Allow multiple modifiers for property promotion

Fixes issue #800.
This commit is contained in:
Nikita Popov 2021-08-08 19:12:44 +02:00
parent 5a43015499
commit 9aebf377fc
4 changed files with 914 additions and 864 deletions

View File

@ -530,24 +530,29 @@ non_empty_parameter_list:
| non_empty_parameter_list ',' parameter { push($1, $3); } | non_empty_parameter_list ',' parameter { push($1, $3); }
; ;
optional_visibility_modifier: optional_property_modifiers:
/* empty */ { $$ = 0; } /* empty */ { $$ = 0; }
| T_PUBLIC { $$ = Stmt\Class_::MODIFIER_PUBLIC; } | optional_property_modifiers property_modifier
{ $this->checkModifier($1, $2, #2); $$ = $1 | $2; }
;
property_modifier:
T_PUBLIC { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
| T_PROTECTED { $$ = Stmt\Class_::MODIFIER_PROTECTED; } | T_PROTECTED { $$ = Stmt\Class_::MODIFIER_PROTECTED; }
| T_PRIVATE { $$ = Stmt\Class_::MODIFIER_PRIVATE; } | T_PRIVATE { $$ = Stmt\Class_::MODIFIER_PRIVATE; }
| T_READONLY { $$ = Stmt\Class_::MODIFIER_READONLY; } | T_READONLY { $$ = Stmt\Class_::MODIFIER_READONLY; }
; ;
parameter: parameter:
optional_attributes optional_visibility_modifier optional_type_without_static optional_attributes optional_property_modifiers optional_type_without_static
optional_arg_ref optional_ellipsis plain_variable optional_arg_ref optional_ellipsis plain_variable
{ $$ = new Node\Param($6, null, $3, $4, $5, attributes(), $2, $1); { $$ = new Node\Param($6, null, $3, $4, $5, attributes(), $2, $1);
$this->checkParam($$); } $this->checkParam($$); }
| optional_attributes optional_visibility_modifier optional_type_without_static | optional_attributes optional_property_modifiers optional_type_without_static
optional_arg_ref optional_ellipsis plain_variable '=' expr optional_arg_ref optional_ellipsis plain_variable '=' expr
{ $$ = new Node\Param($6, $8, $3, $4, $5, attributes(), $2, $1); { $$ = new Node\Param($6, $8, $3, $4, $5, attributes(), $2, $1);
$this->checkParam($$); } $this->checkParam($$); }
| optional_attributes optional_visibility_modifier optional_type_without_static | optional_attributes optional_property_modifiers optional_type_without_static
optional_arg_ref optional_ellipsis error optional_arg_ref optional_ellipsis error
{ $$ = new Node\Param(Expr\Error[], null, $3, $4, $5, attributes(), $2, $1); } { $$ = new Node\Param(Expr\Error[], null, $3, $4, $5, attributes(), $2, $1); }
; ;

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@ class Point {
public function __construct( public function __construct(
public float $x = 0.0, public float $x = 0.0,
protected array $y = [], protected array $y = [],
private string $z = 'hello' private string $z = 'hello',
public readonly int $a = 0,
) {} ) {}
} }
----- -----
@ -81,6 +82,22 @@ array(
value: hello value: hello
) )
) )
3: Param(
attrGroups: array(
)
flags: MODIFIER_PUBLIC | MODIFIER_READONLY (65)
type: Identifier(
name: int
)
byRef: false
variadic: false
var: Expr_Variable(
name: a
)
default: Scalar_LNumber(
value: 0
)
)
) )
returnType: null returnType: null
stmts: array( stmts: array(

View File

@ -8,6 +8,7 @@ class Point
public float $x = 0.0, public float $x = 0.0,
protected array $y = [], protected array $y = [],
private string $z = 'hello', private string $z = 'hello',
public readonly int $a = 0,
) { ) {
} }
} }
@ -15,7 +16,7 @@ class Point
!!php7 !!php7
class Point class Point
{ {
public function __construct(public float $x = 0.0, protected array $y = [], private string $z = 'hello') public function __construct(public float $x = 0.0, protected array $y = [], private string $z = 'hello', public readonly int $a = 0)
{ {
} }
} }