Type: fix incorrect usage of hasRuntimeBits

Closes #13962
This commit is contained in:
Veikka Tuominen 2022-12-16 00:23:22 +02:00
parent 58caed1c71
commit 728dd29f1a
2 changed files with 13 additions and 2 deletions

View File

@ -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 };
}

View File

@ -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));
}