diff --git a/compiler/parser/src/parser/type_.rs b/compiler/parser/src/parser/type_.rs index f634fee8ed..1d4f100581 100644 --- a/compiler/parser/src/parser/type_.rs +++ b/compiler/parser/src/parser/type_.rs @@ -75,6 +75,8 @@ impl ParserContext<'_> { })?; if dims.is_empty() && !had_item_err { self.emit_err(ParserError::array_tuple_dimensions_empty(&span)); + } else if dims.len() == 1 { + self.emit_err(ParserError::invalid_parens_around_single_array_dimension_size(&span)); } ArrayDimensions(dims.into()) }) diff --git a/leo/errors/src/parser/parser_errors.rs b/leo/errors/src/parser/parser_errors.rs index aad2d6896f..08a5905e44 100644 --- a/leo/errors/src/parser/parser_errors.rs +++ b/leo/errors/src/parser/parser_errors.rs @@ -390,4 +390,12 @@ create_errors!( msg: "do not put parens around single variable names", help: None, } + + /// For when a user puts parens around a single defined variable. + @formatted + invalid_parens_around_single_array_dimension_size { + args: (), + msg: "do not put parens around single dimension array size", + help: None, + } ); diff --git a/tests/expectations/parser/parser/expression/array_init.leo.out b/tests/expectations/parser/parser/expression/array_init.leo.out index bf542ace05..cd7972a8d9 100644 --- a/tests/expectations/parser/parser/expression/array_init.leo.out +++ b/tests/expectations/parser/parser/expression/array_init.leo.out @@ -45,27 +45,6 @@ outputs: col_stop: 7 path: "" content: "[0; 1]" - - ArrayInit: - element: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 3 - path: "" - content: "[0; (1)]" - dimensions: - - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "[0; (1)]" - ArrayInit: element: Value: diff --git a/tests/expectations/parser/parser/expression/array_init_fail.leo.out b/tests/expectations/parser/parser/expression/array_init_fail.leo.out index d8a72305fd..c38384b2b3 100644 --- a/tests/expectations/parser/parser/expression/array_init_fail.leo.out +++ b/tests/expectations/parser/parser/expression/array_init_fail.leo.out @@ -5,3 +5,4 @@ outputs: - "Error [EPAR0370010]: illegal spread in array initializer\n --> test:1:1\n |\n 1 | [...0u8; 1]\n | ^^^^^^^" - "Error [EPAR0370010]: illegal spread in array initializer\n --> test:1:1\n |\n 1 | [...0; 1]\n | ^^^^^" - "Error [EPAR0370023]: Array dimensions specified as a tuple cannot be empty.\n --> test:1:5\n |\n 1 | [0; ()]\n | ^^" + - "Error [EPAR0370045]: do not put parens around single dimension array size\n --> test:1:5\n |\n 1 | [0; (1)]\n | ^^^" diff --git a/tests/expectations/parser/parser/expression/array_len.leo.out b/tests/expectations/parser/parser/expression/array_len.leo.out index 5d31cbeb55..1007e7ea87 100644 --- a/tests/expectations/parser/parser/expression/array_len.leo.out +++ b/tests/expectations/parser/parser/expression/array_len.leo.out @@ -89,49 +89,6 @@ outputs: col_stop: 13 path: "" content: "[0; 1].len()" - - Call: - function: - Access: - Member: - inner: - ArrayInit: - element: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 3 - path: "" - content: "[0; (1)].len()" - dimensions: - - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "[0; (1)].len()" - name: "{\"name\":\"len\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"[0; (1)].len()\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 13 - path: "" - content: "[0; (1)].len()" - type_: ~ - arguments: [] - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 15 - path: "" - content: "[0; (1)].len()" - Call: function: Access: diff --git a/tests/parser/expression/array_init.leo b/tests/parser/expression/array_init.leo index 343be881e7..38826f66e7 100644 --- a/tests/parser/expression/array_init.leo +++ b/tests/parser/expression/array_init.leo @@ -7,8 +7,6 @@ expectation: Pass [0; 1] -[0; (1)] - [0; (1, 2)] [0; (1, 2,)] diff --git a/tests/parser/expression/array_init_fail.leo b/tests/parser/expression/array_init_fail.leo index 8cd5b5eb0b..95b21d3199 100644 --- a/tests/parser/expression/array_init_fail.leo +++ b/tests/parser/expression/array_init_fail.leo @@ -9,3 +9,5 @@ expectation: Fail [...0; 1] [0; ()] + +[0; (1)] \ No newline at end of file diff --git a/tests/parser/expression/array_len.leo b/tests/parser/expression/array_len.leo index 4a67f8d2b6..eb59228e67 100644 --- a/tests/parser/expression/array_len.leo +++ b/tests/parser/expression/array_len.leo @@ -7,8 +7,6 @@ expectation: Pass [0; 1].len() -[0; (1)].len() - [0; (1, 2)].len() [0; (1, 2, 3)].len()