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

Struct assignment happens out of order #15158

Closed
Radvendii opened this issue Apr 2, 2023 · 1 comment
Closed

Struct assignment happens out of order #15158

Radvendii opened this issue Apr 2, 2023 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@Radvendii
Copy link
Sponsor

Zig Version

0.10.1

Steps to Reproduce and Observed Behavior

  • Create a struct with more than one field
  • Modify both fields simultaneously, with reference to the previously set fields

Minimal reproduction here: https://github.com/proqqul/RHS-first
Just run zig build test

const expect = @import("std").testing.expect;

const Struct = struct {
    a: bool,
    b: bool,
};

test "RHS first" {
    var s = Struct{
        .a = true,
        .b = true,
    };

    // RHS should be evaluated first, yielding .{ .a = false, .b = true} before
    // assignment occurs. In fact, we see the opposite, and s.a gets assigned
    // `false` before s.a gets evaluated in the next line.
    s = .{
        .a = false,
        .b = s.a,
    };
    try expect(s.b);
}

Expected Behavior

RHS of assignment will be fully evaluated before assignment occurs

@Radvendii Radvendii added the bug Observed behavior contradicts documented or intended behavior label Apr 2, 2023
@Radvendii
Copy link
Sponsor Author

whoops! duplicate of #12064

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

1 participant