zig icon indicating copy to clipboard operation
zig copied to clipboard

std.Io compile error: group.async

Open YannickFricke opened this issue 2 months ago • 2 comments

Zig Version

0.16.0-dev.1399+7b325e08c

Steps to Reproduce and Observed Behavior

/home/yfr/.local/share/mise/installs/zig/master/lib/std/Io.zig:1041:17: error: error union is ignored
                @call(.auto, function, args_casted.*);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/yfr/.local/share/mise/installs/zig/master/lib/std/Io.zig:1041:17: note: consider using 'try', 'catch', or 'if'

The line which the error refers to: https://github.com/ziglang/zig/blob/7b325e08c9b401b723345c33d12a37a832dedfab/lib/std/Io.zig#L1041

Expected Behavior

zig should be able to compile the standard library

Simple fix

When the error union should be given back to the caller then this would be a possible fix:

pub fn async(g: *Group, io: Io, function: anytype, args: std.meta.ArgsTuple(@TypeOf(function))) !void {
        const Args = @TypeOf(args);
        const TypeErased = struct {
            fn start(group: *Group, context: *const anyopaque) void {
                _ = group;
                const args_casted: *const Args = @ptrCast(@alignCast(context));
                try @call(.auto, function, args_casted.*);
            }
        };
        io.vtable.groupAsync(io.userdata, g, @ptrCast(&args), .of(Args), TypeErased.start);
    }

YannickFricke avatar Nov 21 '25 12:11 YannickFricke

You need also change fn start signature in std.Io.VTable to return !void, so you actually could use try inside. But that raises question about groupAsync comment, that says:

This mode does not support results, await, or cancel.

Yet, groupCancel exists.

floatdrop avatar Nov 21 '25 13:11 floatdrop

I checked on this with @kristoff-it it totally makes sense that std.Io.Group.async/3 should be given a function which does not return an error union (which resolves the compile error).

Maybe we could improve the error message in this case?

YannickFricke avatar Nov 21 '25 13:11 YannickFricke