diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-28 22:38:48 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-30 00:18:08 +0300 |
| commit | d26d696ee01d3a17d17cde24c8841e7f551ba5f2 (patch) | |
| tree | 96b165fba9084df59da2e2c4a83420787d6d4798 /lib | |
| parent | 4758752e5d64a3e36086483de569188f62519bac (diff) | |
| download | zig-d26d696ee01d3a17d17cde24c8841e7f551ba5f2.tar.gz zig-d26d696ee01d3a17d17cde24c8841e7f551ba5f2.zip | |
parser: require expression after colon in slice expr
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/zig/parse.zig | 2 | ||||
| -rw-r--r-- | lib/std/zig/parser_test.zig | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index f3c219cfc6..2a7d2623ef 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -3257,7 +3257,7 @@ const Parser = struct { if (p.eatToken(.ellipsis2)) |_| { const end_expr = try p.parseExpr(); if (p.eatToken(.colon)) |_| { - const sentinel = try p.parseExpr(); + const sentinel = try p.expectExpr(); _ = try p.expectToken(.r_bracket); return p.addNode(.{ .tag = .slice_sentinel, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 38c2960f31..a74d53f21c 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -5118,6 +5118,14 @@ test "zig fmt: while continue expr" { }); } +test "zig fmt: error for missing sentinel value in sentinel slice" { + try testError( + \\const foo = foo[0..:]; + , &[_]Error{ + .expected_expr, + }); +} + test "zig fmt: error for invalid bit range" { try testError( \\var x: []align(0:0:0)u8 = bar; |
