Skip to content

Commit

Permalink
Type: fix incorrect usage of hasRuntimeBits
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Dec 15, 2022
1 parent 6453585 commit 5665862
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3475,7 +3475,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);
Expand Down Expand Up @@ -3504,7 +3507,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 };
}
Expand Down
5 changes: 5 additions & 0 deletions test/behavior/sizeof_and_typeof.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 5665862

Please sign in to comment.