Hi guys,
have a look at the following code, it is a pasting of Zig compiler https://codeberg.org/ziglang/zig/src/commit/9636d76b6d26d142f7d23e6d25eec1c28cf571b4/src/Zcu/PerThread.zig#L2445
const imported_mod: ?*Module = m: {
if (mem.eql(u8, import_string, "std")) break :m zcu.std_mod;
if (mem.eql(u8, import_string, "root")) break :m zcu.root_mod;
if (mem.eql(u8, import_string, "builtin")) {
const opts = importer.mod.?.getBuiltinOptions(zcu.comp.config);
break :m zcu.builtin_modules.get(opts.hash()).?;
}
break :m importer.mod.?.deps.get(import_string);
};
it seems the m: block will never break an optional value :
- in the first 2 cases , zcu.std_mod and zcu.root_mod has type *Module
- in the rest , any null value will panic
so imported_mod will never be null, what I’ve missed ?