zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 1b62a22268117340ee7a17f019df01cd39ec1421 (tree)
parent 9720bade7a0165d4e6dc7bf4fafb895f2e458a3b
Author: David Rubin <daviru007@icloud.com>
Date:   Wed,  5 Mar 2025 18:20:15 -0800

Sema: increment extra index even if return type is generic

Diffstat:
Msrc/Sema.zig | 7++++---
Mtest/behavior/generics.zig | 25+++++++++++++++++++++++++
2 files changed, 29 insertions(+), 3 deletions(-)

diff --git 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 @@ -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; +}