Closed
Description
const std = @import("std");
pub fn main() !void {
// Read from user input to convince compiler to not optimize out conditional
const stdin = std.io.getStdIn().reader();
var buf: [10]u8 = undefined;
const n = try stdin.read(&buf);
const f = if (n % 2 == 0) "hi" else "world"; // works
const g = .{if (n % 2 == 0) "hi" else "world"}; // doesn't work
std.debug.print("{}, {}\n", .{ f, g });
}
f
correctly recognizes that it should be a []const u8
, but that coercion doesn't happen inside of the anonymous struct g
, which is unexpected!
Metadata
Metadata
Assignees
Labels
No labels