Skip to content

whole struct value assignment can fail #9722

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

Closed
francescoalemanno opened this issue Sep 9, 2021 · 1 comment
Closed

whole struct value assignment can fail #9722

francescoalemanno opened this issue Sep 9, 2021 · 1 comment
Milestone

Comments

@francescoalemanno
Copy link
Contributor

const Pair = struct {
    x: i64,
    y: i64,
    const Self = @This();
    pub fn swap(self: Self) Self {
        return Self{ .x = self.y, .y = self.x };
    }
};

pub fn main() !void {
    var p = Pair{ .x = 1, .y = 10 };
    p = p.swap();
    print("{}", .{p});
}

expected result:

Pair{ .x = 10, .y = 1 }

actual result:

Pair{ .x = 10, .y = 10 }

on zig 0.9.0-dev.927+eb5e4ac49

@travisstaloch
Copy link
Contributor

duplicate of #4021

@andrewrk andrewrk added this to the 0.9.0 milestone Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants