Skip to content

The Print is broken when I use a single line If statement #12454

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
haz00 opened this issue Aug 16, 2022 · 1 comment
Closed

The Print is broken when I use a single line If statement #12454

haz00 opened this issue Aug 16, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@haz00
Copy link

haz00 commented Aug 16, 2022

Zig Version

0.10.0-dev.3559+d2342370f

Steps to Reproduce

This is broken, prints: ...

const std = @import("std");

pub fn main() !void {
    const arr = [_]u8{0} ** 3;

    for (arr) |_, idx| {
        std.debug.print("{s}", .{ if (idx % 2 == 0) "." else "-"});
    }
}

Expected Behavior

The valid result must be .-.

This is valid code:

const std = @import("std");

pub fn main() !void {
    const arr = [_]u8{0} ** 3;

    for (arr) |_, idx| {
        var str = if (idx % 2 == 0) "." else "-";
        std.debug.print("{s}", .{ str });
    }
}

Actual Behavior

No errors, just incorrect result from If expression.

@haz00 haz00 added the bug Observed behavior contradicts documented or intended behavior label Aug 16, 2022
@tauoverpi
Copy link
Contributor

duplicate of #5230, note that this works with -fno-stage1

@ifreund ifreund closed this as completed Aug 16, 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

No branches or pull requests

3 participants