commit 84000aa820de2d00571f7e8fde5d3973e2fdc441 (tree)
parent 8fa88c88c28420d89392a9984748070d35f18321
Author: Veikka Tuominen <git@vexu.eu>
Date: Sun, 5 Jun 2022 20:36:56 +0300
Sema: fix inline call of func using ret_ptr with comptime only type
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git 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
@@ -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);
+}