mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
parent
58caed1c71
commit
728dd29f1a
10
src/type.zig
10
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 };
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user