authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-28 22:38:48+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-30 00:18:08+03:00
logd26d696ee01d3a17d17cde24c8841e7f551ba5f2
tree96b165fba9084df59da2e2c4a83420787d6d4798
parent4758752e5d64a3e36086483de569188f62519bac

parser: require expression after colon in slice expr


2 files changed, 9 insertions(+), 1 deletions(-)

lib/std/zig/parse.zig+1-1
......@@ -3257,7 +3257,7 @@ const Parser = struct {
32573257 if (p.eatToken(.ellipsis2)) |_| {
32583258 const end_expr = try p.parseExpr();
32593259 if (p.eatToken(.colon)) |_| {
3260 const sentinel = try p.parseExpr();
3260 const sentinel = try p.expectExpr();
32613261 _ = try p.expectToken(.r_bracket);
32623262 return p.addNode(.{
32633263 .tag = .slice_sentinel,
lib/std/zig/parser_test.zig+8
......@@ -5118,6 +5118,14 @@ test "zig fmt: while continue expr" {
51185118 });
51195119}
51205120
5121test "zig fmt: error for missing sentinel value in sentinel slice" {
5122 try testError(
5123 \\const foo = foo[0..:];
5124 , &[_]Error{
5125 .expected_expr,
5126 });
5127}
5128
51215129test "zig fmt: error for invalid bit range" {
51225130 try testError(
51235131 \\var x: []align(0:0:0)u8 = bar;