aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-12-28 15:10:12 +0200
committerVeikka Tuominen <git@vexu.eu>2022-12-29 12:42:44 +0200
commit9a0c593a547eec03a527afaac13fcf11f799c20f (patch)
treeb0b111e8f3d4c21c49a6d634102b85a9ae9934a7 /test/behavior/struct.zig
parent7350f0d9b5aecaf98998bc6591a649d9a7b7091f (diff)
downloadzig-9a0c593a547eec03a527afaac13fcf11f799c20f.tar.gz
zig-9a0c593a547eec03a527afaac13fcf11f799c20f.zip
add tests for fixed stage1 bugs
Closes #1957 Closes #1994 Closes #2140 Closes #2746 Closes #2802 Closes #2855 Closes #2895 Closes #2981 Closes #3054 Closes #3158 Closes #3234 Closes #3259 Closes #3371 Closes #3376 Closes #3387 Closes #3529 Closes #3653 Closes #3750 Closes #3778 Closes #3882 Closes #3915 Closes #3929 Closes #3961 Closes #3988 Closes #4123 Closes #7448
Diffstat (limited to 'test/behavior/struct.zig')
-rw-r--r--test/behavior/struct.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index 041b8ddcd8..dfed7d276e 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -1458,3 +1458,40 @@ test "struct has only one reference" {
try expectEqual(@sizeOf(struct { x: u16 }), S.optionalComptimeIntParam(@sizeOf(struct { x: u16 })));
try expectEqual(@sizeOf(struct { x: u32 }), S.errorUnionComptimeIntParam(@sizeOf(struct { x: u32 })));
}
+
+test "no dependency loop on pointer to optional struct" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ const A = struct { b: B };
+ const B = struct { a: *?A };
+ };
+ var a1: ?S.A = null;
+ var a2: ?S.A = .{ .b = .{ .a = &a1 } };
+ a1 = .{ .b = .{ .a = &a2 } };
+
+ try expect(a1.?.b.a == &a2);
+ try expect(a2.?.b.a == &a1);
+}
+
+test "discarded struct initialization works as expected" {
+ const S = struct { a: u32 };
+ _ = S{ .a = 1 };
+}
+
+test "function pointer in struct returns the struct" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const A = struct {
+ const A = @This();
+ f: *const fn () A,
+
+ fn f() A {
+ return .{ .f = f };
+ }
+ };
+ var a = A.f();
+ try expect(a.f == A.f);
+}