mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Sema: fix inline call of func using ret_ptr with comptime only type
This commit is contained in:
parent
8fa88c88c2
commit
84000aa820
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user