diff --git a/src/Sema.zig b/src/Sema.zig index 012bfb3a5c..54be47f584 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -26017,13 +26017,12 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A break :cc .auto; }; - const ret_ty: Type = if (extra.data.bits.ret_ty_is_generic) - .generic_poison - else if (extra.data.bits.has_ret_ty_body) blk: { + const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: { const body_len = sema.code.extra[extra_index]; extra_index += 1; const body = sema.code.bodySlice(extra_index, body_len); extra_index += body.len; + if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison; const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ .simple = .function_ret_ty }); const ty = val.toType(); @@ -26031,6 +26030,8 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A } else if (extra.data.bits.has_ret_ty_ref) blk: { const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); extra_index += 1; + if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison; + const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref); const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty }); break :blk ret_ty_val.toType(); diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index 50c329d721..4fc07f7b6f 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -646,3 +646,28 @@ test "generic struct captures slice of another struct" { const T = S.Bar(&S.foo_array); comptime std.debug.assert(T.foo_ptr == &S.foo_array); } + +test "noalias paramters with generic return type" { + const S = struct { + pub fn a(noalias _: *u8, im_noalias: usize) im_noalias {} + pub fn b(noalias _: *u8, im_noalias: usize, x: *isize) x { + _ = im_noalias; + } + pub fn c(noalias _: *u8, im_noalias: usize, x: isize) struct { x } { + _ = im_noalias; + } + pub fn d(noalias _: *u8, im_noalias: usize, _: anytype) struct { im_noalias } {} + pub fn e(noalias _: *u8, _: usize, im_noalias: [5]u9) switch (@TypeOf(im_noalias)) { + else => void, + } {} + pub fn f(noalias _: *u8, _: anytype, im_noalias: u8) switch (@TypeOf(im_noalias)) { + else => enum { x, y, z }, + } {} + }; + _ = S.a; + _ = S.b; + _ = S.c; + _ = S.d; + _ = S.e; + _ = S.f; +}