summaryrefslogtreecommitdiff
path: root/src/syntax/parser.rs
diff options
context:
space:
mode:
authorMarmare314 <49279081+Marmare314@users.noreply.github.com>2023-04-13 16:07:58 +0200
committerGitHub <noreply@github.com>2023-04-13 16:07:58 +0200
commit0105eb7382801b56781308ea94b3aeffa6fd867f (patch)
tree9374989fb8999f4d1ca1362c8b96679cc61be9e0 /src/syntax/parser.rs
parentd1cd814ef8149cbac6e59c81e074aa59c930eed3 (diff)
Fix function sinks (#638)
Diffstat (limited to 'src/syntax/parser.rs')
-rw-r--r--src/syntax/parser.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs
index 42183f3a..7c05eebc 100644
--- a/src/syntax/parser.rs
+++ b/src/syntax/parser.rs
@@ -1069,6 +1069,7 @@ fn validate_dict(p: &mut Parser, m: Marker) {
}
fn validate_params(p: &mut Parser, m: Marker) {
+ let mut used_spread = false;
let mut used = HashSet::new();
for child in p.post_process(m) {
match child.kind() {
@@ -1086,12 +1087,24 @@ fn validate_params(p: &mut Parser, m: Marker) {
}
SyntaxKind::Spread => {
let Some(within) = child.children_mut().last_mut() else { continue };
- if within.kind() != SyntaxKind::Ident {
+ if used_spread {
+ child.convert_to_error("only one argument sink is allowed");
+ continue;
+ }
+ used_spread = true;
+ if within.kind() == SyntaxKind::Dots {
+ continue;
+ } else if within.kind() != SyntaxKind::Ident {
within.convert_to_error(eco_format!(
"expected identifier, found {}",
within.kind().name(),
));
child.make_erroneous();
+ continue;
+ }
+ if !used.insert(within.text().clone()) {
+ within.convert_to_error("duplicate parameter");
+ child.make_erroneous();
}
}
SyntaxKind::LeftParen | SyntaxKind::RightParen | SyntaxKind::Comma => {}