authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-16 00:23:22+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-17 13:22:09+02:00
log728dd29f1ac4e75111fec0299e50cf94c6a78760
treef3433e259b121c8ac33ef3d38a9e895162c45806
parent58caed1c71179f48c4e7bffadef0392fa8381e72

Type: fix incorrect usage of `hasRuntimeBits`

Closes #13962

2 files changed, 13 insertions(+), 2 deletions(-)

src/type.zig+8-2
...@@ -3489,7 +3489,10 @@ pub const Type = extern union {...@@ -3489,7 +3489,10 @@ pub const Type = extern union {
3489 return AbiSizeAdvanced{ .scalar = 0 };3489 return AbiSizeAdvanced{ .scalar = 0 };
3490 }3490 }
34913491
3492 if (!child_type.hasRuntimeBits()) return AbiSizeAdvanced{ .scalar = 1 };3492 if (!(child_type.hasRuntimeBitsAdvanced(false, strat) catch |err| switch (err) {
3493 error.NeedLazy => return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(strat.lazy, ty) },
3494 else => |e| return e,
3495 })) return AbiSizeAdvanced{ .scalar = 1 };
34933496
3494 if (ty.optionalReprIsPayload()) {3497 if (ty.optionalReprIsPayload()) {
3495 return abiSizeAdvanced(child_type, target, strat);3498 return abiSizeAdvanced(child_type, target, strat);
...@@ -3518,7 +3521,10 @@ pub const Type = extern union {...@@ -3518,7 +3521,10 @@ pub const Type = extern union {
3518 // in abiAlignmentAdvanced.3521 // in abiAlignmentAdvanced.
3519 const data = ty.castTag(.error_union).?.data;3522 const data = ty.castTag(.error_union).?.data;
3520 const code_size = abiSize(Type.anyerror, target);3523 const code_size = abiSize(Type.anyerror, target);
3521 if (!data.payload.hasRuntimeBits()) {3524 if (!(data.payload.hasRuntimeBitsAdvanced(false, strat) catch |err| switch (err) {
3525 error.NeedLazy => return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(strat.lazy, ty) },
3526 else => |e| return e,
3527 })) {
3522 // Same as anyerror.3528 // Same as anyerror.
3523 return AbiSizeAdvanced{ .scalar = code_size };3529 return AbiSizeAdvanced{ .scalar = code_size };
3524 }3530 }
test/behavior/sizeof_and_typeof.zig+5
...@@ -288,3 +288,8 @@ test "runtime instructions inside typeof in comptime only scope" {...@@ -288,3 +288,8 @@ test "runtime instructions inside typeof in comptime only scope" {
288 try expect(@TypeOf((T{}).b) == i8);288 try expect(@TypeOf((T{}).b) == i8);
289 }289 }
290}290}
291
292test "@sizeOf optional of previously unresolved union" {
293 const Node = union { a: usize };
294 try expect(@sizeOf(?Node) == @sizeOf(Node) + @alignOf(Node));
295}