authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-06 17:20:27-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-06 17:20:27-05:00
logecb77af5343c58bbd8023ded0ebf241abe1b0dfa
tree6a60bc2870c64f08726841b78f2d63434eaba7e6
parent80a72c225cf2a08e683936921dfda07f93cef1b8
signaturelock-open Commit is signed but in an unrecognized format.

add regression test for fixed bug

closes #3742

2 files changed, 39 insertions(+), 0 deletions(-)

test/stage1/behavior.zig+1
......@@ -38,6 +38,7 @@ comptime {
3838 _ = @import("behavior/bugs/3112.zig");
3939 _ = @import("behavior/bugs/3367.zig");
4040 _ = @import("behavior/bugs/3384.zig");
41 _ = @import("behavior/bugs/3742.zig");
4142 _ = @import("behavior/bugs/394.zig");
4243 _ = @import("behavior/bugs/421.zig");
4344 _ = @import("behavior/bugs/529.zig");
test/stage1/behavior/bugs/3742.zig created+38
......@@ -0,0 +1,38 @@
1const std = @import("std");
2
3pub const GET = struct {
4 key: []const u8,
5
6 pub fn init(key: []const u8) GET {
7 return .{ .key = key };
8 }
9
10 pub const Redis = struct {
11 pub const Command = struct {
12 pub fn serialize(self: GET, comptime rootSerializer: type) void {
13 return rootSerializer.serializeCommand(.{ "GET", self.key });
14 }
15 };
16 };
17};
18
19pub fn isCommand(comptime T: type) bool {
20 const tid = @typeId(T);
21 return (tid == .Struct or tid == .Enum or tid == .Union) and
22 @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");
23}
24
25pub const ArgSerializer = struct {
26 pub fn serializeCommand(command: var) void {
27 const CmdT = @typeOf(command);
28
29 if (comptime isCommand(CmdT)) {
30 // COMMENTING THE NEXT LINE REMOVES THE ERROR
31 return CmdT.Redis.Command.serialize(command, ArgSerializer);
32 }
33 }
34};
35
36test "fixed" {
37 ArgSerializer.serializeCommand(GET.init("banana"));
38}