Why this code doesn't work anymore in master/0.14?

The following code works in 0.13.0:

    const imports = .{
        .{ .name = "zigar", .module = zigar },
    };
    const mod = b.createModule(.{
        .root_source_file = .{ .cwd_relative = cfg.module_path },
        .imports = &imports,
    });

To get my code to compile using the latest master I had to attach a type to imports:

    const imports = [_]std.Build.Module.Import{
        .{ .name = "zigar", .module = zigar },
    };
    const mod = b.createModule(.{
        .root_source_file = .{ .cwd_relative = cfg.module_path },
        .imports = &imports,
    });

Just wondering what got changed.

1 Like

Anonymous struct types have recently been removed:

5 Likes

The following builds correctly:

    const proper_module = b.addModule("proper", .{
        .root_source_file = b.path("src/proper.zig"),
        .imports = &.{
            .{ .name = "recover", .module = recover_module },
        },
    });
2 Likes

Well, that’s confusing. Moving an initializer to a const shouldn’t cause code to fail imho.

    const imports = .{
        .{ .name = "zigar", .module = zigar },
    };

In this code, zig compiler does not know the type of imports.


In the following code, zig compiler can derive the type:

const proper_module = b.addModule("proper", .{
        .root_source_file = b.path("src/proper.zig"),
        .imports = &.{
            .{ .name = "recover", .module = recover_module },
        },
    });

addModule accepts Module.CreateOptions, and its member imports is []const Import.

1 Like

Comptime int, float, and enum literal don’t work this way. Nor do the other comptime-types like null and undefined.