I’ve run into a roadblock where I need to create a Wrap where the type of tail is ?*Wrap. I’d love to be able to do something like this:
const Node = Wrap(InnerType, ?*Node);
But this creates a circular reference which the compiler can not handle.
For a bit of justification, This Wrap function in my code is creating a struct which allows you to have a header and variable length buffer right next to each other in memory much like: https://github.com/ziglang/zig/issues/173
I may be misunderstanding your question (we may need an example to see exactly what you’re going for), but it sounds like you’re looking for a *@This() strategy. Essentially, you’re composing a linked list on the fly… am I right?
Yes, some way of using @This() when supplying inputs to Wrap would be a solution. The example I gave may have been a little too simple to express what I’m trying to do, I can also supply the actual code for Wrap if that would be helpful.
Thanks for the workaround! I probably should have mentioned in my original post that I was trying to avoid this solution, but it does get the job done.
I would really like to see some way of keeping type safety here, but I understand if that’s just not possible.
There are ways to make this type safe, the question is, how much do you need Wrap to do? Will the tail always be an optional example of the type? Is it ok to have two functions, one for when the tail isn’t self-referential, and one for when it is?
This solution is certainly good enough for what I need to accomplish which is great! I think that the only way for comp time defined types to have self referential arguments while not requiring any hacks like this would be to evaluate comp time expressions lazily which would be a pretty big change I’m guessing.