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 08:43:28+02:00
logf2c838d2cf652b7124ef60af1e7fdc5601b51fe1
treeb854010185e94eafca96007b91fc6f26cce14f94
parentedaa9584ccf19878040ffc30a3ace17c20e552a4
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Sema: increment extra index even if return type is generic


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

src/Sema.zig+4-3
...@@ -26641,13 +26641,12 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26641,13 +26641,12 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26641 break :cc .auto;26641 break :cc .auto;
26642 };26642 };
2664326643
26644 const ret_ty: Type = if (extra.data.bits.ret_ty_is_generic)26644 const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: {
26645 .generic_poison
26646 else if (extra.data.bits.has_ret_ty_body) blk: {
26647 const body_len = sema.code.extra[extra_index];26645 const body_len = sema.code.extra[extra_index];
26648 extra_index += 1;26646 extra_index += 1;
26649 const body = sema.code.bodySlice(extra_index, body_len);26647 const body = sema.code.bodySlice(extra_index, body_len);
26650 extra_index += body.len;26648 extra_index += body.len;
26649 if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison;
2665126650
26652 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ .simple = .function_ret_ty });26651 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ .simple = .function_ret_ty });
26653 const ty = val.toType();26652 const ty = val.toType();
...@@ -26655,6 +26654,8 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26655,6 +26654,8 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26655 } else if (extra.data.bits.has_ret_ty_ref) blk: {26654 } else if (extra.data.bits.has_ret_ty_ref) blk: {
26656 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);26655 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
26657 extra_index += 1;26656 extra_index += 1;
26657 if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison;
26658
26658 const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref);26659 const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref);
26659 const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty });26660 const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty });
26660 break :blk ret_ty_val.toType();26661 break :blk ret_ty_val.toType();
test/behavior/generics.zig+25
...@@ -646,3 +646,28 @@ test "generic struct captures slice of another struct" {...@@ -646,3 +646,28 @@ test "generic struct captures slice of another struct" {
646 const T = S.Bar(&S.foo_array);646 const T = S.Bar(&S.foo_array);
647 comptime std.debug.assert(T.foo_ptr == &S.foo_array);647 comptime std.debug.assert(T.foo_ptr == &S.foo_array);
648}648}
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}