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

translate-c: Incorrect code generated for cast-to-union #10955

Closed
ehaas opened this issue Feb 21, 2022 · 0 comments · Fixed by #10964
Closed

translate-c: Incorrect code generated for cast-to-union #10955

ehaas opened this issue Feb 21, 2022 · 0 comments · Fixed by #10964
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@ehaas
Copy link
Sponsor Contributor

ehaas commented Feb 21, 2022

Zig Version

0.10.0-dev.870+65aa33319

Steps to Reproduce

Run zig translate-c on the following:

union U {
    long l;
    double d;
};

void foo(void) {
    union U u = (union U) 42L;
}

Expected Behavior

The union cast should be translated into something like this:

var u: union_U = union_U{ .l = @as(c_long, 42) };

Actual Behavior

The union cast is translated like this, which does not compile:

var u: union_U = @as(union_U, @as(c_long, 42));
@ehaas ehaas added the bug Observed behavior contradicts documented or intended behavior label Feb 21, 2022
ehaas added a commit to ehaas/zig that referenced this issue Feb 21, 2022
ehaas added a commit to ehaas/zig that referenced this issue Feb 22, 2022
ehaas added a commit to ehaas/zig that referenced this issue Feb 23, 2022
Vexu pushed a commit that referenced this issue Feb 23, 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

Successfully merging a pull request may close this issue.

1 participant