Having trouble generating types

Am creating some types and generate struct with function with default types and then crate a @Struct with it, in Positional.zig I have a GenerateOptiond which seems to have a well define struct but, in Command.zig fails telling that is not a well defined struct.

using master with commit a85a29ae4d3f
Here is the repo https://codeberg.org/SillyProgramming/Zark/src/branch/Prototype
Current Error:

src/Command.zig:173:27: error: comptime dereference requires 'Command.GenerateOption(&.{}[0..0])' to have a well-defined layout
        self.options.attrs[0..self.options.attrs.len],
        ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
src/Command.zig:50:12: note: struct declared here
    return struct { desc: []const u8 = desc };
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.zig:56:45: note: called at comptime here
    const commandGenerate = command.Generate();
                            ~~~~~~~~~~~~~~~~^~

Sorry for just skimming thru the code really fast, but do you need to pass your Self as pointer?
It makes it a bit hard to track the changes of the types.

I think so,
It could be by value but it would not possible to modify or add the the arrays, so I need to copy that again inside the function and modify it need to return it to reassing it later

just use &.{}

1 Like

That is because it the struct inside has a defualt value of an empty string, that is what I want, but when i insert something different than a empty string the same happens.

src/Command.zig:173:27: error: comptime dereference requires 'Command.GenerateOption("When"[0..4])' to have a well-defined layout
        self.options.attrs[0..self.options.attrs.len],
        ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
src/Command.zig:50:12: note: struct declared here
    return struct { desc: []const u8 = desc };
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.zig:56:45: note: called at comptime here
    const commandGenerate = command.Generate();
                            ~~~~~~~~~~~~~~~~^~
fn GenerateOption(desc: []const u8) type {
    return struct { desc: []const u8 = desc };
}

I am unsure why comptime dereference requires a well defined layout (because the compiler should know whatever layout it picks), but you could try to use a extern struct for GenerateOption.

The compiler is complaining that Self is not an extern or packed struct, and you’re dereferencing it. If you pass it by value instead of pointer, it should work.

The problem is that in Generate Command.zig it is not a const pointer

Now Command.zig does not work if I modify the arrays,
But why does Positinal.zig work with out problem?

The problem was that when added the new option type the default value was not modified and was the old on, bad error message but welp