add regression test for fixed bug

closes #3742
This commit is contained in:
Andrew Kelley 2019-12-06 17:20:27 -05:00
parent 80a72c225c
commit ecb77af534
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 39 additions and 0 deletions

View File

@ -38,6 +38,7 @@ comptime {
_ = @import("behavior/bugs/3112.zig");
_ = @import("behavior/bugs/3367.zig");
_ = @import("behavior/bugs/3384.zig");
_ = @import("behavior/bugs/3742.zig");
_ = @import("behavior/bugs/394.zig");
_ = @import("behavior/bugs/421.zig");
_ = @import("behavior/bugs/529.zig");

View File

@ -0,0 +1,38 @@
const std = @import("std");
pub const GET = struct {
key: []const u8,
pub fn init(key: []const u8) GET {
return .{ .key = key };
}
pub const Redis = struct {
pub const Command = struct {
pub fn serialize(self: GET, comptime rootSerializer: type) void {
return rootSerializer.serializeCommand(.{ "GET", self.key });
}
};
};
};
pub fn isCommand(comptime T: type) bool {
const tid = @typeId(T);
return (tid == .Struct or tid == .Enum or tid == .Union) and
@hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");
}
pub const ArgSerializer = struct {
pub fn serializeCommand(command: var) void {
const CmdT = @typeOf(command);
if (comptime isCommand(CmdT)) {
// COMMENTING THE NEXT LINE REMOVES THE ERROR
return CmdT.Redis.Command.serialize(command, ArgSerializer);
}
}
};
test "fixed" {
ArgSerializer.serializeCommand(GET.init("banana"));
}