Skip to content

tuple created with wrong value #8036

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
marler8997 opened this issue Feb 18, 2021 · 2 comments
Closed

tuple created with wrong value #8036

marler8997 opened this issue Feb 18, 2021 · 2 comments
Milestone

Comments

@marler8997
Copy link
Contributor

marler8997 commented Feb 18, 2021

Reproduce this issue with:

bug.zig:

const std = @import("std");

pub fn main() void {
    const val : u8 = blk: {
        if (false) break :blk 42;
        break :blk 93;
    };
    std.debug.warn("val is {}\n", .{val});
    const val2 = if (val == 42) @as(u8, 42) else @as(u8, 93);
    std.debug.warn("val2 = {}\n", .{val2});
    const tuple = .{if (val == 42) @as(u8, 42) else @as(u8, 93)};
    std.debug.warn("tuple[0] is {}\n", .{tuple[0]});
    // This assert fails!!!
    //std.debug.assert(val == tuple[0]);
}
$ zig run bug.zig 
val is 93
val2 is 93
tuple[0] is 42

This one boggles my mind. There are alot of places that can be changed that will make this error go away. I'm am perplexed by what combination of sorcery has caused this to happen and now I'm going to be very hesitant at how I use tuples (i.e. what I pass to print/format functions).

@rohlem
Copy link
Contributor

rohlem commented Feb 19, 2021

Probably duplicate/related to #4491, #5230, #6444, #7097, although their names aren't the most descriptive.
To me it seems that branching expressions in tuples / anonymous-list-literals are generally broken/flaky in stage 1.

@marler8997
Copy link
Contributor Author

yup looks like a duplicate of at least one of those :)

@andrewrk andrewrk added this to the 0.8.0 milestone Jun 4, 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