What if I write generic like this
const std = @import("std");
fn StupidGeneric(comptime T: type) type {
const U = struct {
const This = @This();
a: T,
b: T,
fn addThem(thing: This) T {
return thing.a + thing.b;
}
};
return U;
}
pub fn main() void {
const StupidFloat = StupidGeneric(f32);
const sf = StupidFloat{.a = 1.2, .b= 3.4};
std.debug.print("{}\n", .{sf.addThem()});
}
?
This joky example is very similar to yours - we have some struct defined inside a function and therefore we have to use @This()
, otherwise we will get use of undeclared identifier 'U'
.