parser: support first class callables on static method calls

This commit is contained in:
Ryan Chandler 2022-09-15 01:06:42 +01:00
parent 8d6ad8ec0a
commit 17b37157ce
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -2110,6 +2110,16 @@ impl Parser {
unpack = true; unpack = true;
} }
if unpack && self.current.kind == TokenKind::RightParen {
args.push(Arg {
name: None,
unpack: false,
value: Expression::VariadicPlaceholder
});
break;
}
let value = self.expression(Precedence::Lowest)?; let value = self.expression(Precedence::Lowest)?;
args.push(Arg { args.push(Arg {
@ -4045,6 +4055,19 @@ mod tests {
]); ]);
} }
#[test]
fn first_class_callable_static_method() {
assert_ast("<?php A::foo(...);", &[
expr!(Expression::StaticMethodCall { target: Box::new(Expression::Identifier { name: "A".into() }), method: "foo".into(), args: vec![
Arg {
name: None,
unpack: false,
value: Expression::VariadicPlaceholder
}
] })
]);
}
fn assert_ast(source: &str, expected: &[Statement]) { fn assert_ast(source: &str, expected: &[Statement]) {
let mut lexer = Lexer::new(None); let mut lexer = Lexer::new(None);
let tokens = lexer.tokenize(source).unwrap(); let tokens = lexer.tokenize(source).unwrap();