Decl literal fn + catch unreachable causes an error

Is it a bug, isn’t it?

const Decl = struct {
    a: u32,

    pub fn init() error{UnreachableError}!Decl {
        return .{
            .a = 0,
        };
    }
};

pub fn main() !void {
    const a: Decl = .init() catch unreachable; // main.zig:12:22: error: type '@Type(.enum_literal)' not a function
    const b: Decl = try .init(); // OK
    const c: Decl = Decl.init() catch unreachable; // OK
    _ = a;
    _ = b;
    _ = c;
}

Playground link:

2 Likes

Not a bug decl literal cannot be used with `catch` operator · Issue #21289 · ziglang/zig · GitHub

4 Likes