diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 0ce08a1e6a..ecbb46fae0 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -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"); diff --git a/test/stage1/behavior/bugs/3742.zig b/test/stage1/behavior/bugs/3742.zig new file mode 100644 index 0000000000..74aed006f6 --- /dev/null +++ b/test/stage1/behavior/bugs/3742.zig @@ -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")); +}