Syntax error if function name is parenthesized (#3058)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
Heinenen 2024-01-16 09:52:56 +01:00 committed by GitHub
parent f57c34a7ce
commit ad901c2cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 13 deletions

View File

@ -984,8 +984,7 @@ fn args(p: &mut Parser) {
enum PatternKind { enum PatternKind {
Ident, Ident,
Placeholder, Other,
Destructuring,
} }
fn pattern(p: &mut Parser) -> PatternKind { fn pattern(p: &mut Parser) -> PatternKind {
@ -994,14 +993,12 @@ fn pattern(p: &mut Parser) -> PatternKind {
let kind = collection(p, false); let kind = collection(p, false);
validate_pattern_at(p, m, true); validate_pattern_at(p, m, true);
if kind == SyntaxKind::Parenthesized { if kind != SyntaxKind::Parenthesized {
PatternKind::Ident
} else {
p.wrap(m, SyntaxKind::Destructuring); p.wrap(m, SyntaxKind::Destructuring);
PatternKind::Destructuring
} }
PatternKind::Other
} else if p.eat_if(SyntaxKind::Underscore) { } else if p.eat_if(SyntaxKind::Underscore) {
PatternKind::Placeholder PatternKind::Other
} else { } else {
p.expect(SyntaxKind::Ident); p.expect(SyntaxKind::Ident);
PatternKind::Ident PatternKind::Ident
@ -1014,22 +1011,21 @@ fn let_binding(p: &mut Parser) {
let m2 = p.marker(); let m2 = p.marker();
let mut closure = false; let mut closure = false;
let mut destructuring = false; let mut other = false;
match pattern(p) { match pattern(p) {
PatternKind::Ident => { PatternKind::Ident => {
closure = p.directly_at(SyntaxKind::LeftParen); if p.directly_at(SyntaxKind::LeftParen) {
if closure {
let m3 = p.marker(); let m3 = p.marker();
collection(p, false); collection(p, false);
validate_params_at(p, m3); validate_params_at(p, m3);
p.wrap(m3, SyntaxKind::Params); p.wrap(m3, SyntaxKind::Params);
closure = true;
} }
} }
PatternKind::Placeholder => {} PatternKind::Other => other = true,
PatternKind::Destructuring => destructuring = true,
} }
let f = if closure || destructuring { Parser::expect } else { Parser::eat_if }; let f = if closure || other { Parser::expect } else { Parser::eat_if };
if f(p, SyntaxKind::Eq) { if f(p, SyntaxKind::Eq) {
code_expr(p); code_expr(p);
} }

View File

@ -275,3 +275,10 @@ Three
// Error: 15 expected expression // Error: 15 expected expression
#let func(x) = #let func(x) =
---
// Error: 12 expected equals sign
#let (func)(x)
---
// Error: 12 expected equals sign
// Error: 15-15 expected semicolon or line break
#let (func)(x) = 3