You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const std = @import("std");pubfn main()anyerror!void{
var args = std.process.args();
_ = args.skip();const flag = args.skip();return std.fmt.format(std.io.getStdOut().writer(),"{any}\n{s}\n",.{
flag,if(flag) @as([]constu8,"YES") else "NO",});}
zig version: 0.9.0-dev.874+4334dbb9a
When running the program with no arguments, the expected output is:
false
NO
The observed output is:
false
YES
This example was minimized from another example; the general problem seems to be format arguments initialized by a branch between two constant strings, when the branch is not comptime known.
The text was updated successfully, but these errors were encountered:
adlerd
changed the title
Incorrect constant string printed by std.fmt.format
Branch miscompiled as if it were comptime known
Sep 16, 2021
Probably a manifestation/duplicate of the nasty #3882 / #4491 / #5230 / #7097 .
The stage1 compiler is alarmingly buggy with conditional control flow filling tuples.
The current workaround is to write the values to variables first, and use those in the tuple.
I tried running this program
zig version
:0.9.0-dev.874+4334dbb9a
When running the program with no arguments, the expected output is:
The observed output is:
This example was minimized from another example; the general problem seems to be format arguments initialized by a branch between two constant strings, when the branch is not comptime known.
The text was updated successfully, but these errors were encountered: