diff --git a/parser/src/error.rs b/parser/src/error.rs index 89f5366..47096a5 100644 --- a/parser/src/error.rs +++ b/parser/src/error.rs @@ -22,6 +22,7 @@ pub enum LexicalErrorType { TabsAfterSpaces, DefaultArgumentError, PositionalArgumentError, + UnpackedArgumentError, DuplicateKeywordArgumentError, UnrecognizedToken { tok: char }, FStringError(FStringErrorType), @@ -55,6 +56,12 @@ impl fmt::Display for LexicalErrorType { LexicalErrorType::PositionalArgumentError => { write!(f, "positional argument follows keyword argument") } + LexicalErrorType::UnpackedArgumentError => { + write!( + f, + "iterable argument unpacking follows keyword argument unpacking" + ) + } LexicalErrorType::UnrecognizedToken { tok } => { write!(f, "Got unexpected token {tok}") } diff --git a/parser/src/function.rs b/parser/src/function.rs index 0cc934f..4662113 100644 --- a/parser/src/function.rs +++ b/parser/src/function.rs @@ -55,6 +55,7 @@ pub fn parse_args(func_args: Vec) -> Result { @@ -67,6 +68,8 @@ pub fn parse_args(func_args: Vec) -> Result) -> Result { - // Allow starred args after keyword arguments. + // Allow starred arguments after keyword arguments but + // not after double-starred arguments. if !keywords.is_empty() && !is_starred(&value) { return Err(LexicalError { error: LexicalErrorType::PositionalArgumentError, location: value.location, }); + } else if double_starred { + return Err(LexicalError { + error: LexicalErrorType::UnpackedArgumentError, + location: value.location, + }); } args.push(value);