aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-07 17:42:17 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-07 17:42:17 -0700
commit75cecef63ccaffda32b7ec2dd2d6cc3cb0b3d23a (patch)
tree40154037ee31701ccfa3484b7dedefdc8139baea
parenta0c44e806b70021203f5b9cf9af3b5049c40a75a (diff)
downloadzig-75cecef63ccaffda32b7ec2dd2d6cc3cb0b3d23a.tar.gz
zig-75cecef63ccaffda32b7ec2dd2d6cc3cb0b3d23a.zip
stage2: fix returning structs byval from functions
-rw-r--r--src/AstGen.zig2
-rw-r--r--test/behavior/struct.zig15
-rw-r--r--test/behavior/struct_stage1.zig15
3 files changed, 16 insertions, 16 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 614930734a..a3a39c1b57 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -6473,7 +6473,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
.never => {
// Returning a value that cannot be an error; skip error defers.
try genDefers(gz, defer_outer, scope, .normal_only);
- _ = try gz.addUnNode(.ret_node, operand, node);
+ try gz.addRet(rl, operand, node);
return Zir.Inst.Ref.unreachable_value;
},
.always => {
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index d755c92c72..e3b0e4bbff 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -129,3 +129,18 @@ const MemberFnRand = struct {
return r.seed;
}
};
+
+test "return struct byval from function" {
+ const bar = makeBar2(1234, 5678);
+ try expect(bar.y == 5678);
+}
+const Bar = struct {
+ x: i32,
+ y: i32,
+};
+fn makeBar2(x: i32, y: i32) Bar {
+ return Bar{
+ .x = x,
+ .y = y,
+ };
+}
diff --git a/test/behavior/struct_stage1.zig b/test/behavior/struct_stage1.zig
index 3c4aaf58ec..265890105e 100644
--- a/test/behavior/struct_stage1.zig
+++ b/test/behavior/struct_stage1.zig
@@ -61,21 +61,6 @@ test "store member function in variable" {
try expect(result == 1234);
}
-test "return struct byval from function" {
- const bar = makeBar2(1234, 5678);
- try expect(bar.y == 5678);
-}
-const Bar = struct {
- x: i32,
- y: i32,
-};
-fn makeBar2(x: i32, y: i32) Bar {
- return Bar{
- .x = x,
- .y = y,
- };
-}
-
test "empty struct method call" {
const es = EmptyStruct{};
try expect(es.method() == 1234);