Hi,
First time here…
I found an interesting “feature” and I am not sure if it is bug or if I am missing something. I am using the 0.13.0 version of zig.
Here is the code:
const std = @import("std");
fn CreateTuple(comptime len: u8) type {
return struct {
const Self = @This();
fn init() Self { return .{};}
fn addUp(tuple: [len]u32) u32 {
var sum: u32 = 0;
for (tuple) |item| {
sum += item;
}
return sum;
}
};
}
pub fn main() !void {
// const MyTuple = CreateTuple(2).init();
const MyTuple = CreateTuple(2);
std.debug.print("Sum is {}", .{ MyTuple.addUp(.{2, 2}) });
}
This works as expected, but if I uncomment the first line in main(), the compiler complains that ‘addUp’ is not a member function of CreateTuple(2). Calling init() should not change anything in my opinion.