mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Sema: increment extra index even if return type is generic
This commit is contained in:
parent
9720bade7a
commit
1b62a22268
2 changed files with 29 additions and 3 deletions
|
|
@ -26017,13 +26017,12 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
|
||||||
break :cc .auto;
|
break :cc .auto;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ret_ty: Type = if (extra.data.bits.ret_ty_is_generic)
|
const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: {
|
||||||
.generic_poison
|
|
||||||
else if (extra.data.bits.has_ret_ty_body) blk: {
|
|
||||||
const body_len = sema.code.extra[extra_index];
|
const body_len = sema.code.extra[extra_index];
|
||||||
extra_index += 1;
|
extra_index += 1;
|
||||||
const body = sema.code.bodySlice(extra_index, body_len);
|
const body = sema.code.bodySlice(extra_index, body_len);
|
||||||
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 val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ .simple = .function_ret_ty });
|
||||||
const ty = val.toType();
|
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: {
|
} else if (extra.data.bits.has_ret_ty_ref) blk: {
|
||||||
const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
|
const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
|
||||||
extra_index += 1;
|
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_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 });
|
const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty });
|
||||||
break :blk ret_ty_val.toType();
|
break :blk ret_ty_val.toType();
|
||||||
|
|
|
||||||
|
|
@ -646,3 +646,28 @@ test "generic struct captures slice of another struct" {
|
||||||
const T = S.Bar(&S.foo_array);
|
const T = S.Bar(&S.foo_array);
|
||||||
comptime std.debug.assert(T.foo_ptr == &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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue