zig icon indicating copy to clipboard operation
zig copied to clipboard

ICE involving empty slice of anonymous struct type

Open poconn opened this issue 1 year ago • 0 comments

Zig Version

0.14.0-dev.944+0e99f517f

Steps to Reproduce and Observed Behavior

The compiler segfaults on the following code:

export fn f() void {
    // Does not work (but works if moved to after the below call):
    try g(&.{});
    // Works:
    try g(&.{.{.{}}});
}

fn g(x: []const struct { S }) !void {
    h(x);
}

fn h(_: []const struct { S }) void {}

pub const S = packed struct {};

https://godbolt.org/z/hTv94zaxo

Only when an empty slice is passed to g(), and the other conditions seem really specific. E.g. all of the following avoid the issue:

  • returning void from g()
  • making S non-packed
  • giving the anonymous struct { S } a name

Expected Behavior

Compiles successfully

poconn avatar Aug 08 '24 21:08 poconn