mirror of
https://github.com/ziglang/zig.git
synced 2025-12-24 07:03:11 +00:00
stage2: fix returning structs byval from functions
This commit is contained in:
parent
a0c44e806b
commit
75cecef63c
@ -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 => {
|
||||
|
||||
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user