Parser - Detect duplicate argument names
This commit is contained in:
parent
db781ed00f
commit
29d3677b2a
1 changed files with 11 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast,
|
ast,
|
||||||
errors::{ErrorHandler, ParserError},
|
errors::{ErrorHandler, ParserError},
|
||||||
|
@ -251,6 +253,7 @@ impl Parser {
|
||||||
|
|
||||||
let mut params = Vec::new();
|
let mut params = Vec::new();
|
||||||
if self.expect(&[TokenType::RightParen]).is_none() {
|
if self.expect(&[TokenType::RightParen]).is_none() {
|
||||||
|
let mut names: HashSet<String> = HashSet::new();
|
||||||
loop {
|
loop {
|
||||||
if params.len() >= kind.max_params() {
|
if params.len() >= kind.max_params() {
|
||||||
return Err(ParserError::new(
|
return Err(ParserError::new(
|
||||||
|
@ -262,7 +265,14 @@ impl Parser {
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if let TokenType::Identifier(_) = self.peek().token_type {
|
if let TokenType::Identifier(name) = &self.peek().token_type {
|
||||||
|
if names.contains(name) {
|
||||||
|
return Err(ParserError::new(
|
||||||
|
self.peek(),
|
||||||
|
&format!("duplicate {} parameter", kind.name()),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
names.insert(name.to_owned());
|
||||||
params.push(self.advance().clone());
|
params.push(self.advance().clone());
|
||||||
} else {
|
} else {
|
||||||
return Err(ParserError::new(self.peek(), "parameter name expected"));
|
return Err(ParserError::new(self.peek(), "parameter name expected"));
|
||||||
|
|
Loading…
Reference in a new issue