diff --git a/src/compilation_error.rs b/src/compilation_error.rs index 5105b8b0aa..305025cb30 100644 --- a/src/compilation_error.rs +++ b/src/compilation_error.rs @@ -213,13 +213,6 @@ impl Display for CompilationError<'_> { UnterminatedBacktick => { writeln!(f, "Unterminated backtick")?; }, - ZeroOrMoreVariadicParameterHasDefault { parameter } => { - writeln!( - f, - "Variadic parameter `{}` accepting zero or more arguments has a default value", - parameter - )?; - }, Internal { ref message } => { writeln!( f, diff --git a/src/compilation_error_kind.rs b/src/compilation_error_kind.rs index 786cdeb719..32832ff86f 100644 --- a/src/compilation_error_kind.rs +++ b/src/compilation_error_kind.rs @@ -93,7 +93,4 @@ pub(crate) enum CompilationErrorKind<'src> { UnterminatedInterpolation, UnterminatedString, UnterminatedBacktick, - ZeroOrMoreVariadicParameterHasDefault { - parameter: &'src str, - }, } diff --git a/src/parser.rs b/src/parser.rs index 977d128144..11104fd68c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -571,16 +571,10 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { fn parse_parameter(&mut self, kind: ParameterKind) -> CompilationResult<'src, Parameter<'src>> { let name = self.parse_name()?; - let default = match (self.accepted(Equals)?, kind) { - (true, ParameterKind::Star) => { - return Err(self.next()?.error( - CompilationErrorKind::ZeroOrMoreVariadicParameterHasDefault { - parameter: name.lexeme(), - }, - )); - }, - (true, _) => Some(self.parse_value()?), - _ => None, + let default = if self.accepted(Equals)? { + Some(self.parse_value()?) + } else { + None }; Ok(Parameter { diff --git a/tests/integration.rs b/tests/integration.rs index e66e3e0f6f..1ebd70a4b3 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1860,19 +1860,25 @@ a x y *z: } test! { - name: star_variadic_disallows_default, + name: star_variadic_ignore_default, justfile: " -a x y *z='': +a x y *z='HELLO': echo {{x}} {{y}} {{z}} ", - args: ("a", "0", "1"), - stdout: "", - stderr: "error: Variadic parameter `z` accepting zero or more arguments has a default value - | -2 | a x y *z='': - | ^^ + args: ("a", "0", "1", "2", "3", " 4 "), + stdout: "0 1 2 3 4\n", + stderr: "echo 0 1 2 3 4 \n", +} + +test! { + name: star_variadic_use_default, + justfile: " +a x y *z='HELLO': + echo {{x}} {{y}} {{z}} ", - status: EXIT_FAILURE, + args: ("a", "0", "1"), + stdout: "0 1 HELLO\n", + stderr: "echo 0 1 HELLO\n", } test! {