Skip to content

Commit

Permalink
#74 dupe() methods fail to compile (#75)
Browse files Browse the repository at this point in the history
* reproducing the issue

* dupe can only make allocator errors, and this was hard to handle for the compiler.
  • Loading branch information
Arwalk authored Oct 27, 2024
1 parent ff5c9bb commit 9619cfe
Show file tree
Hide file tree
Showing 23 changed files with 2,800 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/protobuf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ pub fn pb_dupe(comptime T: type, original: T, allocator: Allocator) !T {
}

/// Internal dupe function for a specific field
fn dupe_field(original: anytype, comptime field_name: []const u8, comptime ftype: FieldType, allocator: Allocator) !@TypeOf(@field(original, field_name)) {
fn dupe_field(original: anytype, comptime field_name: []const u8, comptime ftype: FieldType, allocator: Allocator) Allocator.Error!@TypeOf(@field(original, field_name)) {
switch (ftype) {
.Varint, .FixedInt => {
return @field(original, field_name);
Expand Down
95 changes: 95 additions & 0 deletions tests/generated/opentelemetry/proto/common/v1.pb.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Code generated by protoc-gen-zig
///! package opentelemetry.proto.common.v1
const std = @import("std");
const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList;

const protobuf = @import("protobuf");
const ManagedString = protobuf.ManagedString;
const fd = protobuf.fd;

pub const AnyValue = struct {
value: ?value_union,

pub const _value_case = enum {
string_value,
bool_value,
int_value,
double_value,
array_value,
kvlist_value,
bytes_value,
};
pub const value_union = union(_value_case) {
string_value: ManagedString,
bool_value: bool,
int_value: i64,
double_value: f64,
array_value: ArrayValue,
kvlist_value: KeyValueList,
bytes_value: ManagedString,
pub const _union_desc = .{
.string_value = fd(1, .String),
.bool_value = fd(2, .{ .Varint = .Simple }),
.int_value = fd(3, .{ .Varint = .Simple }),
.double_value = fd(4, .{ .FixedInt = .I64 }),
.array_value = fd(5, .{ .SubMessage = {} }),
.kvlist_value = fd(6, .{ .SubMessage = {} }),
.bytes_value = fd(7, .Bytes),
};
};

pub const _desc_table = .{
.value = fd(null, .{ .OneOf = value_union }),
};

pub usingnamespace protobuf.MessageMixins(@This());
};

pub const ArrayValue = struct {
values: ArrayList(AnyValue),

pub const _desc_table = .{
.values = fd(1, .{ .List = .{ .SubMessage = {} } }),
};

pub usingnamespace protobuf.MessageMixins(@This());
};

pub const KeyValueList = struct {
values: ArrayList(KeyValue),

pub const _desc_table = .{
.values = fd(1, .{ .List = .{ .SubMessage = {} } }),
};

pub usingnamespace protobuf.MessageMixins(@This());
};

pub const KeyValue = struct {
key: ManagedString = .Empty,
value: ?AnyValue = null,

pub const _desc_table = .{
.key = fd(1, .String),
.value = fd(2, .{ .SubMessage = {} }),
};

pub usingnamespace protobuf.MessageMixins(@This());
};

pub const InstrumentationScope = struct {
name: ManagedString = .Empty,
version: ManagedString = .Empty,
attributes: ArrayList(KeyValue),
dropped_attributes_count: u32 = 0,

pub const _desc_table = .{
.name = fd(1, .String),
.version = fd(2, .String),
.attributes = fd(3, .{ .List = .{ .SubMessage = {} } }),
.dropped_attributes_count = fd(4, .{ .Varint = .Simple }),
};

pub usingnamespace protobuf.MessageMixins(@This());
};
Loading

0 comments on commit 9619cfe

Please sign in to comment.