Skip to content

Can't return anonymous struct literal if return type includes error #3662

@ghost

Description

const Struct = struct {field: u32};
fn func() !Struct {
    return .{.field = 4}; 
}
pub fn main() !void {
    const value = try func();
    @import("std").debug.warn("{}\n", value.field);
}
Semantic Analysis [670/690] /home/dbandstra/host/asdf.zig:3:14: error: type '@typeOf(func).ReturnType.ErrorSet!Struct' does not support struct initialization syntax
    return .{.field = 4};
             ^
/home/dbandstra/host/asdf.zig:6:19: note: referenced here
    const value = try func();
                  ^
/home/dbandstra/zig/build/lib/zig/std/special/start.zig:242:40: note: referenced here
            const result = root.main() catch |err| {
                                       ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions