From 3290e728339e49765b1adda78f173befb9fc12bf Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 25 Jun 2018 11:52:18 -0400 Subject: [PATCH] std.zig.ast: fix incorrect impl of FnProto.firstToken closes #1151 --- std/zig/ast.zig | 1 + std/zig/parser_test.zig | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/std/zig/ast.zig b/std/zig/ast.zig index 4246a50861..63518c5182 100644 --- a/std/zig/ast.zig +++ b/std/zig/ast.zig @@ -858,6 +858,7 @@ pub const Node = struct { pub fn firstToken(self: *FnProto) TokenIndex { if (self.visib_token) |visib_token| return visib_token; + if (self.async_attr) |async_attr| return async_attr.firstToken(); if (self.extern_export_inline_token) |extern_export_inline_token| return extern_export_inline_token; assert(self.lib_name == null); if (self.cc_token) |cc_token| return cc_token; diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig index 09ea8aa1a1..21259bec3c 100644 --- a/std/zig/parser_test.zig +++ b/std/zig/parser_test.zig @@ -1,3 +1,12 @@ +test "zig fmt: preserve space between async fn definitions" { + try testCanonical( + \\async fn a() void {} + \\ + \\async fn b() void {} + \\ + ); +} + test "zig fmt: comment to disable/enable zig fmt first" { try testCanonical( \\// Test trailing comma syntax