0

the issue

Code:

// Type your code here, or load an example.
const std = @import("std");

export fn main() void {
    works();
    //failsAtComptime();
}

fn works() void {
    const test_cases = .{
        [_]u8{},
        [_]u8{0x01},
    };

    inline for (test_cases) |case| {
        std.debug.print("{any}", .{&case});
    }
}

// Differences described in comments
fn failsAtComptime() void {
    // We instead make the test cases into a tupe *of tuples*...
    const test_cases = .{
        .{0, [_]u8{}},
        .{1, [_]u8{0x01}},
    };

    inline for (test_cases) |case| {
        // ...which is unpacked into the same values as in `works()`
        std.debug.print("{any}", .{&case[1]});
    }
}

Link to code on CompilerExplorer.

Specifically, the function works() ...works. And the function failsAtComptime() fails to compile, with an error code (139 for zig version 0.10.0, and 133 for zig trunk as of posting) but no error message.

Notably, this works if I change the print values to the raw arrays case/case[1], instead of the array pointers &case/&case[1].

question

what's going wrong with failsAtComptime? Is this a user error (me?), or a compiler issue, or an error with CompilerExplorer?

CrepeGoat
  • 2,315
  • 20
  • 24
  • 2
    I think you should open a bug report for Zig. I don't think it's a user error if the compiler crashes with no reasonable error message. (FYI I get `Trace/breakpoint trap`, which I think is what return code 133 means, using Zig `0.11.0-dev.2620+23ac4dd87`) – mkrieger1 May 25 '23 at 17:02
  • @mkrieger1 yeahhhh fair point. I always ask SO first by habit, so I don't bug the lang maintainers with user issues. But you're right, this is quite bizarre. And if you repro'd it on your machine then it's not just CompilerExplorer. thanks! – CrepeGoat May 25 '23 at 17:23

0 Answers0