Skip to content

Commit 0850199

Browse files
committed
Don't make VariadicPlaceholder an expression
And don't store it in an Arg.
1 parent b5234ea commit 0850199

File tree

7 files changed

+18
-44
lines changed

7 files changed

+18
-44
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Version 4.12.1-dev
66
* [PHP 8.1] Added support for intersection types using a new `IntersectionType` node.
77
* [PHP 8.1] Added support for explicit octal literals.
88
* [PHP 8.1] Added support for first-class callables. These are represented using a call whose first
9-
`Arg->expr` is an `Expr\VariadicPlaceholder`. The representation is intended to be
10-
forward-compatible with partial function application, just like the PHP feature itself.
9+
argument is a `VariadicPlaceholder`. The representation is intended to be forward-compatible with
10+
partial function application, just like the PHP feature itself.
1111

1212
Version 4.12.0 (2021-07-21)
1313
---------------------------

grammar/php7.y

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,7 @@ argument_list:
623623
;
624624

625625
variadic_placeholder:
626-
T_ELLIPSIS
627-
{ $$ = Node\Arg[Node\VariadicPlaceholder[], false, false]; }
626+
T_ELLIPSIS { $$ = Node\VariadicPlaceholder[]; }
628627
;
629628

630629
non_empty_argument_list:

lib/PhpParser/Node/Arg.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PhpParser\Node;
44

5-
use PhpParser\Node\Expr\VariadicPlaceholder;
5+
use PhpParser\Node\VariadicPlaceholder;
66
use PhpParser\NodeAbstract;
77

88
class Arg extends NodeAbstract

lib/PhpParser/Node/Expr/VariadicPlaceholder.php renamed to lib/PhpParser/Node/VariadicPlaceholder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php declare(strict_types=1);
22

3-
namespace PhpParser\Node\Expr;
3+
namespace PhpParser\Node;
44

5-
use PhpParser\Node\Expr;
5+
use PhpParser\NodeAbstract;
66

77
/**
88
* Represents the "..." in "foo(...)" of the first-class callable syntax.
99
*/
10-
class VariadicPlaceholder extends Expr {
10+
class VariadicPlaceholder extends NodeAbstract {
1111
/**
1212
* Create a variadic argument placeholder (first-class callable syntax).
1313
*
@@ -18,7 +18,7 @@ public function __construct(array $attributes = []) {
1818
}
1919

2020
public function getType(): string {
21-
return 'Expr_VariadicPlaceholder';
21+
return 'VariadicPlaceholder';
2222
}
2323

2424
public function getSubNodeNames(): array {

lib/PhpParser/Parser/Php7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ protected function initReduceCallbacks() {
19341934
$this->semValue = array($this->semStack[$stackPos-(3-2)]);
19351935
},
19361936
310 => function ($stackPos) {
1937-
$this->semValue = new Node\Arg(new Expr\VariadicPlaceholder($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes), false, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes);
1937+
$this->semValue = new Node\VariadicPlaceholder($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes);
19381938
},
19391939
311 => function ($stackPos) {
19401940
$this->semValue = array($this->semStack[$stackPos-(1-1)]);

lib/PhpParser/PrettyPrinter/Standard.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ protected function pArg(Node\Arg $node) {
3333
. $this->p($node->value);
3434
}
3535

36+
protected function pVariadicPlaceholder(Node\VariadicPlaceholder $node) {
37+
return '...';
38+
}
39+
3640
protected function pConst(Node\Const_ $node) {
3741
return $node->name . ' = ' . $this->p($node->value);
3842
}
@@ -692,10 +696,6 @@ protected function pExpr_Yield(Expr\Yield_ $node) {
692696
}
693697
}
694698

695-
protected function pExpr_VariadicPlaceholder(Expr\VariadicPlaceholder $node) {
696-
return '...';
697-
}
698-
699699
// Declarations
700700

701701
protected function pStmt_Namespace(Stmt\Namespace_ $node) {

test/code/parser/expr/firstClassCallables.test

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ array(
2121
)
2222
)
2323
args: array(
24-
0: Arg(
25-
name: null
26-
value: Expr_VariadicPlaceholder(
27-
)
28-
byRef: false
29-
unpack: false
24+
0: VariadicPlaceholder(
3025
)
3126
)
3227
)
@@ -40,12 +35,7 @@ array(
4035
name: foo
4136
)
4237
args: array(
43-
0: Arg(
44-
name: null
45-
value: Expr_VariadicPlaceholder(
46-
)
47-
byRef: false
48-
unpack: false
38+
0: VariadicPlaceholder(
4939
)
5040
)
5141
)
@@ -61,12 +51,7 @@ array(
6151
name: foo
6252
)
6353
args: array(
64-
0: Arg(
65-
name: null
66-
value: Expr_VariadicPlaceholder(
67-
)
68-
byRef: false
69-
unpack: false
54+
0: VariadicPlaceholder(
7055
)
7156
)
7257
)
@@ -79,12 +64,7 @@ array(
7964
)
8065
)
8166
args: array(
82-
0: Arg(
83-
name: null
84-
value: Expr_VariadicPlaceholder(
85-
)
86-
byRef: false
87-
unpack: false
67+
0: VariadicPlaceholder(
8868
)
8969
)
9070
comments: array(
@@ -106,12 +86,7 @@ array(
10686
)
10787
)
10888
args: array(
109-
0: Arg(
110-
name: null
111-
value: Expr_VariadicPlaceholder(
112-
)
113-
byRef: false
114-
unpack: false
89+
0: VariadicPlaceholder(
11590
)
11691
)
11792
)

0 commit comments

Comments
 (0)