diff --git a/src/modules/expression/literal/array.rs b/src/modules/expression/literal/array.rs index c6138e2f..bbdd3374 100644 --- a/src/modules/expression/literal/array.rs +++ b/src/modules/expression/literal/array.rs @@ -50,6 +50,9 @@ impl SyntaxModule for Array { if token(meta, "[").is_ok() { return error!(meta, tok, "Arrays cannot be nested due to the Bash limitations") } + if token(meta, "]").is_ok() { + break; + } // Parse array value let mut value = Expr::new(); syntax(meta, &mut value)?; diff --git a/src/tests/validity.rs b/src/tests/validity.rs index ea663a7f..60dbddd4 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -534,6 +534,15 @@ fn array_init() { test_amber!(code, "1 2 3 4 5"); } +#[test] +fn array_init_with_trailing_comma() { + let code = " + let a = [1, 2, 3, 4, 5,] + echo a + "; + test_amber!(code, "1 2 3 4 5"); +} + #[test] fn array_assign() { let code = "