Not sure if duplicate.
Without the "value" member, there is a compile error on bar = ... (wrong type) as there should be.
With the "value" member, there's an abort.
(zig 0.4.0+805f9b30)
broken LLVM module found: Call parameter type does not match function signature!
%foo = alloca %Foo, align 4
{ %Foo, i16 }* call fastcc void @Foo.init(%Foo* sret %foo, %builtin.StackTrace* %0), !dbg !1138
Unable to dump stack trace: debug info stripped
Aborted
const std = @import("std");
const Foo = struct {
value: u32,
fn init() anyerror!Foo {
var mb = Foo{ .value = 42 };
return mb;
}
};
const Bar = struct {
fn init() anyerror!Bar {
var mb = Bar{};
return mb;
}
};
test "With member" {
var foo: Foo = undefined;
foo = Foo.init();
}
// test "Without member" {
// var bar: Bar = undefined;
// bar = Bar.init();
// }
Related #3269
Found this as well. Minimal test case should be this:
fn throws() ![]u8 {
return error.Failure;
}
const Type = struct {
pixels: []u8,
};
pub fn main() void
{
var data = Type {
.pixels = throws(), // assigning an error union to a field value
};
}
Most helpful comment
Found this as well. Minimal test case should be this: