Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@sizeOf is incorrect for optional unions #13962

Closed
jwhear opened this issue Dec 15, 2022 · 0 comments
Closed

@sizeOf is incorrect for optional unions #13962

jwhear opened this issue Dec 15, 2022 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@jwhear
Copy link
Contributor

jwhear commented Dec 15, 2022

Zig Version

0.11.0-dev.811+8ff9284c4

Steps to Reproduce and Observed Behavior

Using @sizeOf on an optional union produces a value of 1.

const std = @import("std");
pub fn main() !void {
    const Node = union {
        a: usize,
    };
    var output = std.io.getStdOut().writer();
    inline for (.{ ?Node, Node, }) |typ| {
        try output.print("{s} is {} bytes, align is {}\n", .{ @typeName(typ), @sizeOf(typ), @alignOf(typ) });
    }
}

With 0.11.0-dev.811+8ff9284c4 this prints

?test.main.Node is 1 bytes, align is 8
test.main.Node is 8 bytes, align is 8

With 0.10.0 and -fstage1 this prints

?Node is 16 bytes, align is 8
Node is 8 bytes, align is 8

Expected Behavior

The stage1 behavior appears correct.

@jwhear jwhear added the bug Observed behavior contradicts documented or intended behavior label Dec 15, 2022
@Vexu Vexu added this to the 0.10.1 milestone Dec 15, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 15, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 15, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants