Commit 84000aa820
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);
}
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);
+}