mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-18 18:45:23 +00:00
add arg_name in duplicate argument error msg
This commit is contained in:
parent
eccfa7dfee
commit
5b40f2297c
2 changed files with 6 additions and 6 deletions
|
@ -21,7 +21,7 @@ pub enum LexicalErrorType {
|
||||||
TabError,
|
TabError,
|
||||||
TabsAfterSpaces,
|
TabsAfterSpaces,
|
||||||
DefaultArgumentError,
|
DefaultArgumentError,
|
||||||
DuplicateArgumentError,
|
DuplicateArgumentError(String),
|
||||||
PositionalArgumentError,
|
PositionalArgumentError,
|
||||||
UnpackedArgumentError,
|
UnpackedArgumentError,
|
||||||
DuplicateKeywordArgumentError,
|
DuplicateKeywordArgumentError,
|
||||||
|
@ -51,8 +51,8 @@ impl fmt::Display for LexicalErrorType {
|
||||||
LexicalErrorType::DefaultArgumentError => {
|
LexicalErrorType::DefaultArgumentError => {
|
||||||
write!(f, "non-default argument follows default argument")
|
write!(f, "non-default argument follows default argument")
|
||||||
}
|
}
|
||||||
LexicalErrorType::DuplicateArgumentError => {
|
LexicalErrorType::DuplicateArgumentError(arg_name) => {
|
||||||
write!(f, "duplicate argument in function definition")
|
write!(f, "duplicate argument '{arg_name}' in function definition")
|
||||||
}
|
}
|
||||||
LexicalErrorType::DuplicateKeywordArgumentError => {
|
LexicalErrorType::DuplicateKeywordArgumentError => {
|
||||||
write!(f, "keyword argument repeated")
|
write!(f, "keyword argument repeated")
|
||||||
|
|
|
@ -31,16 +31,16 @@ pub fn validate_arguments(
|
||||||
let mut all_arg_names =
|
let mut all_arg_names =
|
||||||
FxHashSet::with_hasher(Default::default());
|
FxHashSet::with_hasher(Default::default());
|
||||||
for arg in all_args {
|
for arg in all_args {
|
||||||
let arg_name = arg.node.arg.clone();
|
let arg_name = &arg.node.arg;
|
||||||
if !all_arg_names.insert(arg_name) {
|
if !all_arg_names.insert(arg_name) {
|
||||||
return Err(LexicalError {
|
return Err(LexicalError {
|
||||||
error: LexicalErrorType::DuplicateArgumentError,
|
error: LexicalErrorType::DuplicateArgumentError(arg_name.to_string()),
|
||||||
location: arg.location,
|
location: arg.location,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(arguments);
|
Ok(arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_params(
|
pub fn parse_params(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue