aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-09-25 22:18:43 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-25 22:18:43 -0700
commit1f2f9f05c254374044d8c30cce6f299d7a18da72 (patch)
tree868df45684a4db5f092b4106e7b17ddb05fbda1e /test/behavior/struct.zig
parent04366576ea4be4959b596ebff7041d17e18d08d8 (diff)
downloadzig-1f2f9f05c254374044d8c30cce6f299d7a18da72.tar.gz
zig-1f2f9f05c254374044d8c30cce6f299d7a18da72.zip
stage2: implement zirCoerceResultPtr
and remove Module.simplePtrType and Module.ptrType in favor of `Type.ptr`.
Diffstat (limited to 'test/behavior/struct.zig')
-rw-r--r--test/behavior/struct.zig38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index e048848799..2dde3c930d 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -52,3 +52,41 @@ fn testFoo(foo: StructFoo) !void {
fn testMutation(foo: *StructFoo) void {
foo.c = 100;
}
+
+test "struct byval assign" {
+ var foo1: StructFoo = undefined;
+ var foo2: StructFoo = undefined;
+
+ foo1.a = 1234;
+ foo2.a = 0;
+ try expect(foo2.a == 0);
+ foo2 = foo1;
+ try expect(foo2.a == 1234);
+}
+
+const Node = struct {
+ val: Val,
+ next: *Node,
+};
+
+const Val = struct {
+ x: i32,
+};
+
+test "struct initializer" {
+ const val = Val{ .x = 42 };
+ try expect(val.x == 42);
+}
+
+const MemberFnTestFoo = struct {
+ x: i32,
+ fn member(foo: MemberFnTestFoo) i32 {
+ return foo.x;
+ }
+};
+
+test "call member function directly" {
+ const instance = MemberFnTestFoo{ .x = 1234 };
+ const result = MemberFnTestFoo.member(instance);
+ try expect(result == 1234);
+}