Skip to content

stage1 if expression returns wrong result or fails to compile #13004

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
peteruhnak opened this issue Sep 28, 2022 · 1 comment
Closed

stage1 if expression returns wrong result or fails to compile #13004

peteruhnak opened this issue Sep 28, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@peteruhnak
Copy link

Zig Version

0.10.0-dev.4197+9a2f17f9f

Steps to Reproduce

linux x86-64

pub fn main() !void {
    // works fine
    std.log.info("'{s}'", .{if (0 == 0) "yep" else "nop"});
    std.log.info("'{s}'", .{if (0 == 1) "yep" else "nop"});

    var i: i32 = 0;
    // misbehaves with variable
    std.log.info("'{s}'", .{if (i == 0) "yep" else "NOP"});
    std.log.info("'{s}'", .{if (i == 1) "yep" else "NOP"});

    // these will not compile in fstage1; works correctly in stage2
    // error: expected type '*const [3:0]u8', found '*const [4:0]u8'
    // std.log.info("'{s}'", .{if (i == 0) "yep" else "nope"});
    // std.log.info("'{s}'", .{if (i == 1) "yep" else "nope"});
}

Expected Behavior

> zig build run         
info: 'yep'
info: 'NOP'
info: 'yep'
info: 'NOP'
info: 'yep'
info: 'NOPE'

Actual Behavior

> zig build run -fstage1
info: 'yep'
info: 'NOP'
info: 'yep'
info: 'yep' // should be NOP
// compile error with the last two statements uncommented
@peteruhnak peteruhnak added the bug Observed behavior contradicts documented or intended behavior label Sep 28, 2022
@peteruhnak
Copy link
Author

duplicate of #5230

@peteruhnak peteruhnak closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 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

1 participant