mirror of
https://github.com/ziglang/zig.git
synced 2025-12-27 00:23:22 +00:00
parent
80a72c225c
commit
ecb77af534
@ -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");
|
||||
|
||||
38
test/stage1/behavior/bugs/3742.zig
Normal file
38
test/stage1/behavior/bugs/3742.zig
Normal 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"));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user