aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2021-02-24 12:14:15 +0100
committerIsaac Freund <ifreund@ifreund.xyz>2021-02-24 12:14:15 +0100
commit1b8eca030e9dac51361d80428f8276a09f31a8c2 (patch)
treeb869bdbd5da5ad8b2b7e261b46b80f8d57010865
parentdb4c15be507a55f63b7f19dd4cdc10717f44eb06 (diff)
downloadzig-1b8eca030e9dac51361d80428f8276a09f31a8c2.tar.gz
zig-1b8eca030e9dac51361d80428f8276a09f31a8c2.zip
zig fmt: fix firstToken() for switch_case
-rw-r--r--lib/std/zig/ast.zig2
-rw-r--r--lib/std/zig/parser_test.zig25
2 files changed, 13 insertions, 14 deletions
diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig
index f2418f7c11..46b58e9465 100644
--- a/lib/std/zig/ast.zig
+++ b/lib/std/zig/ast.zig
@@ -580,7 +580,7 @@ pub const Tree = struct {
.switch_case => {
const extra = tree.extraData(datas[n].lhs, Node.SubRange);
assert(extra.end - extra.start > 0);
- n = extra.start;
+ n = tree.extra_data[extra.start];
},
.asm_output, .asm_input => {
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index 6b81f9a16e..c0d8a012c9 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -4189,19 +4189,18 @@ test "zig fmt: respect extra newline between fn and pub usingnamespace" {
);
}
-// TODO
-//test "zig fmt: respect extra newline between switch items" {
-// try testCanonical(
-// \\const a = switch (b) {
-// \\ .c => {},
-// \\
-// \\ .d,
-// \\ .e,
-// \\ => f,
-// \\};
-// \\
-// );
-//}
+test "zig fmt: respect extra newline between switch items" {
+ try testCanonical(
+ \\const a = switch (b) {
+ \\ .c => {},
+ \\
+ \\ .d,
+ \\ .e,
+ \\ => f,
+ \\};
+ \\
+ );
+}
test "zig fmt: error for invalid bit range" {
try testError(