Take this example of a function that returns a type.
pub fn CallableFunction(comptime FnType: type) type {
return struct {
address: *anyopaque,
pub fn init(function: Function) @This() {
return .{
.address = function.codegen.allocation,
};
}
pub fn call(self: @This(), args: anytype) @typeInfo(FnType).@"fn".return_type.? {
const fn_ptr: *const FnType = @ptrCast(self.address);
return @call(.never_inline, fn_ptr, args);
}
};
}
And now this example usage:
const some_function = try context.chimera.create(0); // : (Function)
const callbable_function = Chimera.CallableFunction(fn (u32) u32).init(some_function); // : (CallableFunction(fn (u32) u32))
const result = callbable_function.call(.{67}); // ((unknown type))
This block compiles fine but the lsp (ZLS) marks result as: ((unknown type))
This is really frustrating as I have to now add another comptime type parameter that will contain the return type which is redundent so I can get the lsp to work properly, for example:
pub fn CallableFunction(comptime FnType: type, comptime Ret: type) type
And then replace any occurence of @typeInfo(FnType).@"fn".return_type.? with Ret.
Is there anyway, I don’t care how complicated but a hack to doing this without having to directly specify the return type (double specifying) like shown: CallableFunction(fn (u32) u32, u32) in hopes of getting rid of unknown_type?
Thanks in advance, really love the language (I came from C++23) but the lsp needs some work (thinking about contributing but don’t know where to start) as I have encountered quite some problems with it.