Add duplicate keyword argument error · RustPython/RustPython@21669a0 · GitHub
Skip to content

Commit 21669a0

Browse files
committed
Add duplicate keyword argument error
Fixes #116
1 parent 51c3f71 commit 21669a0

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/error.rs

Lines changed: 4 additions & 0 deletions

parser/src/function.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::HashSet;
2+
13
use crate::ast;
24
use crate::error::{LexicalError, LexicalErrorType};
35

@@ -6,9 +8,22 @@ type FunctionArgument = (Option<Option<String>>, ast::Expression);
68
pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList, LexicalError> {
79
let mut args = vec![];
810
let mut keywords = vec![];
11+
12+
let mut keyword_names = HashSet::with_capacity(func_args.len());
913
for (name, value) in func_args {
1014
match name {
1115
Some(n) => {
16+
if let Some(keyword_name) = n.clone() {
17+
if keyword_names.contains(&keyword_name) {
18+
return Err(LexicalError {
19+
error: LexicalErrorType::DuplicateKeywordArgumentError,
20+
location: value.location.clone(),
21+
});
22+
}
23+
24+
keyword_names.insert(keyword_name.clone());
25+
}
26+
1227
keywords.push(ast::Keyword { name: n, value });
1328
}
1429
None => {

tests/snippets/function_args.py

Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)