Zig Version
both 0.16.0 and 0.15.2
Steps to Reproduce and Observed Behavior
const std = @import("std");
const Io = std.Io;
const Context = struct {
a: *[4096]u8,
pub fn init(gpa: std.mem.Allocator) !@This() {
const p = try gpa.create([4096]u8);
return .{ .a = p };
}
pub fn deinit(self: @This(), gpa: std.mem.Allocator) void {
gpa.destroy(self.a);
}
};
pub fn main(init: std.process.Init) void {
const context: Context = .init(init.gpa) catch @panic("context init failed");
defer context.deinit(init.gpa);
std.debug.print("{any}\n", .{context});
}
zig build run gives error:
src/main.zig:16:31: error: type '@EnumLiteral()' not a function
const context: Context = .init(init.gpa) catch @panic("context init failed");
Looks like the compiler think .init is a @EnumLiteral() when there's catch clause. use Context.init or remove the catch clause and use a try would works.
Expected Behavior
compiles success.
### Zig Version
both 0.16.0 and 0.15.2
### Steps to Reproduce and Observed Behavior
```
const std = @import("std");
const Io = std.Io;
const Context = struct {
a: *[4096]u8,
pub fn init(gpa: std.mem.Allocator) !@This() {
const p = try gpa.create([4096]u8);
return .{ .a = p };
}
pub fn deinit(self: @This(), gpa: std.mem.Allocator) void {
gpa.destroy(self.a);
}
};
pub fn main(init: std.process.Init) void {
const context: Context = .init(init.gpa) catch @panic("context init failed");
defer context.deinit(init.gpa);
std.debug.print("{any}\n", .{context});
}
```
`zig build run` gives error:
```
src/main.zig:16:31: error: type '@EnumLiteral()' not a function
const context: Context = .init(init.gpa) catch @panic("context init failed");
```
Looks like the compiler think .init is a @EnumLiteral() when there's catch clause. use Context.init or remove the catch clause and use a try would works.
### Expected Behavior
compiles success.