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

This commit is contained in:
Veikka Tuominen 2022-06-05 20:36:56 +03:00 committed by Andrew Kelley
parent 8fa88c88c2
commit 84000aa820
2 changed files with 13 additions and 1 deletions

View File

@ -2526,7 +2526,7 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
const src: LazySrcLoc = .{ .node_offset = inst_data }; const src: LazySrcLoc = .{ .node_offset = inst_data };
try sema.requireFunctionBlock(block, src); 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); const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty);
return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src); return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src);
} }

View File

@ -1074,3 +1074,15 @@ test "switch inside @as gets correct type" {
else => 0, 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);
}