Skip to content

Unwrapped variables alias the original #3352

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
BarabasGitHub opened this issue Sep 30, 2019 · 1 comment
Closed

Unwrapped variables alias the original #3352

BarabasGitHub opened this issue Sep 30, 2019 · 1 comment
Milestone

Comments

@BarabasGitHub
Copy link
Contributor

BarabasGitHub commented Sep 30, 2019

In previous versions of Zig (pre 4.0) they used to be copies, but now they're an alias it seems.

My linked list code which previously worked fine is now broken.

https://github.com/BarabasGitHub/ZigZag/blob/f76697ddcfb10d25e35bc4594db4e605ce871be8/containers/single_linked_list.zig#L20

            pub fn next(self: *Iterator) ?*Value {
                if (self.node) |node| {
                    self.node = node.next;
                    return &node.value;
                } else {
                    return null;
                }
            }

https://github.com/BarabasGitHub/ZigZag/blob/f76697ddcfb10d25e35bc4594db4e605ce871be8/containers/single_linked_list.zig#L47

        pub fn count(self: Self) usize {
            var i = usize(0);
            var node = self.head;
            while (node) |n| {
                node = n.next;
                i += 1;
            }
            return i;
        }

https://github.com/BarabasGitHub/ZigZag/blob/f76697ddcfb10d25e35bc4594db4e605ce871be8/containers/single_linked_list.zig#L88

        pub fn clear(self: *Self) void {
            var node = self.head;
            while (node) |n| {
                node = n.next;
                self.allocator.destroy(n);
            }
            self.head = null;
        }

Maybe this is how it's supposed to work, but it's not very intuitive.

The fix was to make explicit copies, one way or another, see: BarabasGitHub/ZigZag@42148fd#diff-fe4c994cb2028068ff82d5e173fd2bf9

@mikdusan
Copy link
Member

mikdusan commented Oct 1, 2019

duplicate of #2915

@andrewrk andrewrk added this to the 0.6.0 milestone Oct 2, 2019
@andrewrk andrewrk added the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Oct 2, 2019
@andrewrk andrewrk removed the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Feb 15, 2020
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