fix array around 1 element array dim size

This commit is contained in:
gluax 2022-03-14 08:07:01 -07:00
parent 2c30cba70f
commit 9a45c2ae99
8 changed files with 13 additions and 68 deletions

View File

@ -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())
})

View File

@ -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,
}
);

View File

@ -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:

View File

@ -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 | ^^^"

View File

@ -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:

View File

@ -7,8 +7,6 @@ expectation: Pass
[0; 1]
[0; (1)]
[0; (1, 2)]
[0; (1, 2,)]

View File

@ -9,3 +9,5 @@ expectation: Fail
[...0; 1]
[0; ()]
[0; (1)]

View File

@ -7,8 +7,6 @@ expectation: Pass
[0; 1].len()
[0; (1)].len()
[0; (1, 2)].len()
[0; (1, 2, 3)].len()