Skip to content

Commit 673bacf

Browse files
committed
Improve the lookahead check for attributes on expressions
1 parent 3a174a9 commit 673bacf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Parser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,10 @@ private function parseFunctionDeclaration($parentNode) {
680680
*/
681681
private function parseAttributeExpression($parentNode) {
682682
$attributeGroups = $this->parseAttributeGroups(null);
683-
// TODO: Lookahead for static, function, or fn?
684683
// Warn about invalid syntax for attributed declarations
685-
if (in_array($this->token->kind, [TokenKind::FunctionKeyword, TokenKind::FnKeyword, TokenKind::StaticKeyword], true)) {
684+
// Lookahead for static, function, or fn for the only type of expressions that can have attributes (anonymous functions)
685+
if (in_array($this->token->kind, [TokenKind::FunctionKeyword, TokenKind::FnKeyword], true) ||
686+
$this->token->kind === TokenKind::StaticKeyword && $this->lookahead([TokenKind::FunctionKeyword, TokenKind::FnKeyword])) {
686687
$expression = $this->parsePrimaryExpression($parentNode);
687688
} else {
688689
// Create a MissingToken so that diagnostics indicate that the attributes did not match up with an expression/declaration.

0 commit comments

Comments
 (0)