diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-12-21 20:34:27 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-12-21 20:34:27 -0700 |
| commit | 88be5bd81decab792cdb5b749b4bb5cf6d71e877 (patch) | |
| tree | f5eed00970c7e97581e8382ae37d08ef177d431f /test/behavior | |
| parent | 06d751dbb3c9cc4e09f2eb7250a242dc6b2423bc (diff) | |
| download | zig-88be5bd81decab792cdb5b749b4bb5cf6d71e877.tar.gz zig-88be5bd81decab792cdb5b749b4bb5cf6d71e877.zip | |
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.
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/struct_llvm.zig | 11 | ||||
| -rw-r--r-- | test/behavior/struct_stage1.zig | 26 |
2 files changed, 11 insertions, 26 deletions
diff --git a/test/behavior/struct_llvm.zig b/test/behavior/struct_llvm.zig index 5c364e183e..5c8159cb0b 100644 --- a/test/behavior/struct_llvm.zig +++ b/test/behavior/struct_llvm.zig @@ -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; + } +}; diff --git a/test/behavior/struct_stage1.zig b/test/behavior/struct_stage1.zig index 08f6c32aed..7856139c8e 100644 --- a/test/behavior/struct_stage1.zig +++ b/test/behavior/struct_stage1.zig @@ -6,32 +6,6 @@ const expectEqual = std.testing.expectEqual; const expectEqualSlices = std.testing.expectEqualSlices; const maxInt = std.math.maxInt; -const StructFoo = struct { - a: i32, - b: bool, - c: f32, -}; - -const Node = struct { - val: Val, - next: *Node, -}; - -const Val = struct { - x: i32, -}; - -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; - } -}; - const EmptyStruct2 = struct {}; fn testReturnEmptyStructFromFn() EmptyStruct2 { return EmptyStruct2{}; |
