Optional playload can't be comptime values?

For example, the following code triggers a runtime panic instead of a comptime error.

pub fn main() void {
    comptime var t: ?bool = null;
    _ = t.?; // runtime panic instead of comptime error
}

Does any official doc mention this point?

That line runs at runtime so it makes sense, you have to force it with comptime _ = t.?;

1 Like

The weirdness is, sometimes t.? is treated as a comptime value, sometimes it is treated as a runtime value.

var b: bool = true;

pub fn main() void {
    comptime var t: ?bool = false;
    // t.? is viewed as a comptime value.
    t.? = b; // error: cannot store runtime value in compile time variable
}
var b: bool = true;

pub fn main() void {
    comptime var t: ?bool = null;
    // t.? is viewed as a runtime value.
    b = t.?; // panic: attempt to use null value
    t = t;
}