authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-10-24 13:34:07+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-10-24 13:34:07+03:00
log9ffee5abed1e57ceb24e0c8e20aa2fd8c242ca38
tree71029adb4bcd524a33061d3c9c109053c2d171ee
parentc563ba6b15b65ecdc1cb538c9437e11dfb330453
signaturebadge-check Signed by PGP key B5690EEEBB952194

Sema: fix check for whether current AnalUnit is a test function

Closes #21159

2 files changed, 18 insertions(+), 3 deletions(-)

src/Sema.zig+4-3
......@@ -29836,6 +29836,7 @@ fn coerceExtra(
2983629836 if (dest_ty.isGenericPoison()) return inst;
2983729837 const pt = sema.pt;
2983829838 const zcu = pt.zcu;
29839 const ip = &zcu.intern_pool;
2983929840 const dest_ty_src = inst_src; // TODO better source location
2984029841 try dest_ty.resolveFields(pt);
2984129842 const inst_ty = sema.typeOf(inst);
......@@ -30458,7 +30459,7 @@ fn coerceExtra(
3045830459 errdefer msg.destroy(sema.gpa);
3045930460
3046030461 const ret_ty_src: LazySrcLoc = .{
30461 .base_node_inst = sema.getOwnerFuncDeclInst(),
30462 .base_node_inst = ip.getNav(zcu.funcInfo(sema.func_index).owner_nav).srcInst(ip),
3046230463 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
3046330464 };
3046430465 try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{});
......@@ -30496,10 +30497,10 @@ fn coerceExtra(
3049630497
3049730498 // Add notes about function return type
3049830499 if (opts.is_ret and
30499 !zcu.test_functions.contains(zcu.funcInfo(sema.owner.unwrap().func).owner_nav))
30500 !zcu.test_functions.contains(zcu.funcInfo(sema.func_index).owner_nav))
3050030501 {
3050130502 const ret_ty_src: LazySrcLoc = .{
30502 .base_node_inst = sema.getOwnerFuncDeclInst(),
30503 .base_node_inst = ip.getNav(zcu.funcInfo(sema.func_index).owner_nav).srcInst(ip),
3050330504 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
3050430505 };
3050530506 if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) {
test/cases/compile_errors/ret_coercion_error_in_generic_fn_called_from_non_fn_scope.zig created+14
......@@ -0,0 +1,14 @@
1fn foo() fn () void {
2 return struct {};
3}
4comptime {
5 _ = foo();
6}
7
8// error
9// backend=stage2
10// target=native
11//
12// :2:12: error: expected type 'fn () void', found 'type'
13// :1:10: note: function return type declared here
14// :5:12: note: called from here