From 84000aa820de2d00571f7e8fde5d3973e2fdc441 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sun, 5 Jun 2022 20:36:56 +0300 Subject: [PATCH] Sema: fix inline call of func using ret_ptr with comptime only type --- src/Sema.zig | 2 +- test/behavior/basic.zig | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Sema.zig b/src/Sema.zig index 015b50ce4b..5d70ba3a7f 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2526,7 +2526,7 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const src: LazySrcLoc = .{ .node_offset = inst_data }; try sema.requireFunctionBlock(block, src); - if (block.is_comptime) { + if (block.is_comptime or try sema.typeRequiresComptime(block, src, sema.fn_ret_ty)) { const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty); return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src); } diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index dc0e5aaf30..a69df862c1 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -1074,3 +1074,15 @@ test "switch inside @as gets correct type" { else => 0, }); } + +test "inline call of function with a switch inside the return statement" { + const S = struct { + inline fn foo(x: anytype) @TypeOf(x) { + return switch (x) { + 1 => 1, + else => unreachable, + }; + } + }; + try expect(S.foo(1) == 1); +}