Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig test --test-evented-io is broken #9779

Closed
slimsag opened this issue Sep 16, 2021 · 1 comment · Fixed by #9780
Closed

zig test --test-evented-io is broken #9779

slimsag opened this issue Sep 16, 2021 · 1 comment · Fixed by #9780
Milestone

Comments

@slimsag
Copy link
Sponsor Contributor

slimsag commented Sep 16, 2021

With a basic async example:

const std = @import("std");
const expect = std.testing.expect;

var x: i32 = 1;

test "suspend with no resume" {
    var frame = async func();
    try expect(x == 2);
    _ = frame;
}

fn func() void {
    x += 1;
    suspend {}
    // This line is never reached because the suspend has no matching resume.
    x += 1;
}

It fails to compile under zig test --test-evented-io:

$ zig test --test-evented-io main.zig 
/Users/slimsag/Desktop/hexops/zig/build/lib/zig/std/special/test_runner.zig:59:42: error: expected type 'void', found 'std.mem.Allocator.Error'
                    async_frame_buffer = try std.heap.page_allocator.alignedAlloc(u8, std.Target.stack_align, size);
                                         ^
/Users/slimsag/Desktop/hexops/zig/build/lib/zig/std/special/test_runner.zig:19:15: note: function cannot return an error
pub fn main() void {
              ^
@slimsag
Copy link
Sponsor Contributor Author

slimsag commented Sep 16, 2021

PR incoming!

slimsag added a commit to slimsag/zig that referenced this issue Sep 16, 2021
Investigating hexops/zorex#4, I found that `--test-evented-io` is currently broken in
the latest Zig nightly. See ziglang#9779 for a small reproduction.

The issue is that allocation errors here are not correctly handled, as this function
returns `void` and all other error cases `@panic`, the allocation failure should also
use `@panic`.

Fixes ziglang#9779
Helps hexops/zorex#4

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Vexu pushed a commit that referenced this issue Sep 16, 2021
Investigating hexops/zorex#4, I found that `--test-evented-io` is currently broken in
the latest Zig nightly. See #9779 for a small reproduction.

The issue is that allocation errors here are not correctly handled, as this function
returns `void` and all other error cases `@panic`, the allocation failure should also
use `@panic`.

Fixes #9779
Helps hexops/zorex#4

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
@andrewrk andrewrk added this to the 0.9.0 milestone Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants