aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-12-31 14:28:21 +0200
committerAndrew Kelley <andrew@ziglang.org>2022-12-31 20:49:02 -0500
commit58c1d98c1463210135ab7f405d204b0769525328 (patch)
treef174445e9c623e4d367f65f05aaa1ee71fe2d0c4 /test/behavior/struct.zig
parent1c711b0a64a7bd13e5be80dfc107cba9cc9bedc4 (diff)
downloadzig-58c1d98c1463210135ab7f405d204b0769525328.tar.gz
zig-58c1d98c1463210135ab7f405d204b0769525328.zip
add tests for fixed stage1 bugs
Closes #4144 Closes #4255 Closes #4372 Closes #4375 Closes #4380 Closes #4417 Closes #4423 Closes #4476 Closes #4528 Closes #4562 Closes #4572 Closes #4597 Closes #4639 Closes #4672 Closes #4782 Closes #4955 Closes #4984 Closes #4997 Closes #5010 Closes #5114 Closes #5166 Closes #5173 Closes #5276
Diffstat (limited to 'test/behavior/struct.zig')
-rw-r--r--test/behavior/struct.zig60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index dfed7d276e..20a09f92cc 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -1495,3 +1495,63 @@ test "function pointer in struct returns the struct" {
var a = A.f();
try expect(a.f == A.f);
}
+
+test "no dependency loop on optional field wrapped in generic function" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+
+ const S = struct {
+ fn Atomic(comptime T: type) type {
+ return T;
+ }
+ const A = struct { b: Atomic(?*B) };
+ const B = struct { a: ?*A };
+ };
+ var a: S.A = .{ .b = null };
+ var b: S.B = .{ .a = &a };
+ a.b = &b;
+
+ try expect(a.b == &b);
+ try expect(b.a == &a);
+}
+
+test "optional field init with tuple" {
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ a: ?struct { b: u32 },
+ };
+ var a: u32 = 0;
+ var b = S{
+ .a = .{ .b = a },
+ };
+ try expect(b.a.?.b == a);
+}
+
+test "if inside struct init inside if" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const MyStruct = struct { x: u32 };
+ const b: u32 = 5;
+ var i: u32 = 1;
+ var my_var = if (i < 5)
+ MyStruct{
+ .x = 1 + if (i > 0) b else 0,
+ }
+ else
+ MyStruct{
+ .x = 1 + if (i > 0) b else 0,
+ };
+ try expect(my_var.x == 6);
+}
+
+test "optional generic function label struct field" {
+ const Options = struct {
+ isFoo: ?fn (type) u8 = defaultIsFoo,
+ fn defaultIsFoo(comptime _: type) u8 {
+ return 123;
+ }
+ };
+ try expect((Options{}).isFoo.?(u8) == 123);
+}