authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2025-03-05 18:20:15-08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-02 01:34:17+02:00
log1b62a22268117340ee7a17f019df01cd39ec1421
treec59e44ed7876a18bcab19f9340c10d5aa77353a1
parent9720bade7a0165d4e6dc7bf4fafb895f2e458a3b

Sema: increment extra index even if return type is generic


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

src/Sema.zig+4-3
......@@ -26017,13 +26017,12 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2601726017 break :cc .auto;
2601826018 };
2601926019
26020 const ret_ty: Type = if (extra.data.bits.ret_ty_is_generic)
26021 .generic_poison
26022 else if (extra.data.bits.has_ret_ty_body) blk: {
26020 const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: {
2602326021 const body_len = sema.code.extra[extra_index];
2602426022 extra_index += 1;
2602526023 const body = sema.code.bodySlice(extra_index, body_len);
2602626024 extra_index += body.len;
26025 if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison;
2602726026
2602826027 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ .simple = .function_ret_ty });
2602926028 const ty = val.toType();
......@@ -26031,6 +26030,8 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2603126030 } else if (extra.data.bits.has_ret_ty_ref) blk: {
2603226031 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2603326032 extra_index += 1;
26033 if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison;
26034
2603426035 const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref);
2603526036 const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty });
2603626037 break :blk ret_ty_val.toType();
test/behavior/generics.zig+25
......@@ -646,3 +646,28 @@ test "generic struct captures slice of another struct" {
646646 const T = S.Bar(&S.foo_array);
647647 comptime std.debug.assert(T.foo_ptr == &S.foo_array);
648648}
649
650test "noalias paramters with generic return type" {
651 const S = struct {
652 pub fn a(noalias _: *u8, im_noalias: usize) im_noalias {}
653 pub fn b(noalias _: *u8, im_noalias: usize, x: *isize) x {
654 _ = im_noalias;
655 }
656 pub fn c(noalias _: *u8, im_noalias: usize, x: isize) struct { x } {
657 _ = im_noalias;
658 }
659 pub fn d(noalias _: *u8, im_noalias: usize, _: anytype) struct { im_noalias } {}
660 pub fn e(noalias _: *u8, _: usize, im_noalias: [5]u9) switch (@TypeOf(im_noalias)) {
661 else => void,
662 } {}
663 pub fn f(noalias _: *u8, _: anytype, im_noalias: u8) switch (@TypeOf(im_noalias)) {
664 else => enum { x, y, z },
665 } {}
666 };
667 _ = S.a;
668 _ = S.b;
669 _ = S.c;
670 _ = S.d;
671 _ = S.e;
672 _ = S.f;
673}