zig

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

commit 728dd29f1ac4e75111fec0299e50cf94c6a78760 (tree)
parent 58caed1c71179f48c4e7bffadef0392fa8381e72
Author: Veikka Tuominen <git@vexu.eu>
Date:   Fri, 16 Dec 2022 00:23:22 +0200

Type: fix incorrect usage of `hasRuntimeBits`

Closes #13962

Diffstat:
Msrc/type.zig | 10++++++++--
Mtest/behavior/sizeof_and_typeof.zig | 5+++++
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/type.zig b/src/type.zig @@ -3489,7 +3489,10 @@ pub const Type = extern union { return AbiSizeAdvanced{ .scalar = 0 }; } - if (!child_type.hasRuntimeBits()) return AbiSizeAdvanced{ .scalar = 1 }; + if (!(child_type.hasRuntimeBitsAdvanced(false, strat) catch |err| switch (err) { + error.NeedLazy => return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(strat.lazy, ty) }, + else => |e| return e, + })) return AbiSizeAdvanced{ .scalar = 1 }; if (ty.optionalReprIsPayload()) { return abiSizeAdvanced(child_type, target, strat); @@ -3518,7 +3521,10 @@ pub const Type = extern union { // in abiAlignmentAdvanced. const data = ty.castTag(.error_union).?.data; const code_size = abiSize(Type.anyerror, target); - if (!data.payload.hasRuntimeBits()) { + if (!(data.payload.hasRuntimeBitsAdvanced(false, strat) catch |err| switch (err) { + error.NeedLazy => return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(strat.lazy, ty) }, + else => |e| return e, + })) { // Same as anyerror. return AbiSizeAdvanced{ .scalar = code_size }; } diff --git a/test/behavior/sizeof_and_typeof.zig b/test/behavior/sizeof_and_typeof.zig @@ -288,3 +288,8 @@ test "runtime instructions inside typeof in comptime only scope" { try expect(@TypeOf((T{}).b) == i8); } } + +test "@sizeOf optional of previously unresolved union" { + const Node = union { a: usize }; + try expect(@sizeOf(?Node) == @sizeOf(Node) + @alignOf(Node)); +}