Sema: fix empty struct init

* Extract common logic between `zirStructInitEmpty` and
   `zirStructInit`.
 * `resolveTypeFields` additionally sets status to `have_layout` if the
   total number of fields is 0.
This commit is contained in:
Andrew Kelley
2021-12-21 20:34:27 -07:00
parent 06d751dbb3
commit 88be5bd81d
4 changed files with 94 additions and 60 deletions

View File

@@ -66,3 +66,14 @@ test "self-referencing struct via array member" {
x = T{ .children = .{&x} };
try expect(x.children[0] == &x);
}
test "empty struct method call" {
const es = EmptyStruct{};
try expect(es.method() == 1234);
}
const EmptyStruct = struct {
fn method(es: *const EmptyStruct) i32 {
_ = es;
return 1234;
}
};