authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-05 20:36:56+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-06 13:11:50-07:00
log84000aa820de2d00571f7e8fde5d3973e2fdc441
treef6bba6a2098749101eed7ba7a1fa21f8e23dab50
parent8fa88c88c28420d89392a9984748070d35f18321

Sema: fix inline call of func using ret_ptr with comptime only type


2 files changed, 13 insertions(+), 1 deletions(-)

src/Sema.zig+1-1
...@@ -2526,7 +2526,7 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -2526,7 +2526,7 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2526 const src: LazySrcLoc = .{ .node_offset = inst_data };2526 const src: LazySrcLoc = .{ .node_offset = inst_data };
2527 try sema.requireFunctionBlock(block, src);2527 try sema.requireFunctionBlock(block, src);
25282528
2529 if (block.is_comptime) {2529 if (block.is_comptime or try sema.typeRequiresComptime(block, src, sema.fn_ret_ty)) {
2530 const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty);2530 const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty);
2531 return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src);2531 return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src);
2532 }2532 }
test/behavior/basic.zig+12
...@@ -1074,3 +1074,15 @@ test "switch inside @as gets correct type" {...@@ -1074,3 +1074,15 @@ test "switch inside @as gets correct type" {
1074 else => 0,1074 else => 0,
1075 });1075 });
1076}1076}
1077
1078test "inline call of function with a switch inside the return statement" {
1079 const S = struct {
1080 inline fn foo(x: anytype) @TypeOf(x) {
1081 return switch (x) {
1082 1 => 1,
1083 else => unreachable,
1084 };
1085 }
1086 };
1087 try expect(S.foo(1) == 1);
1088}