The following code prints true, but I’m not sure if it will always.
pub fn main() void {
@import(“std”).debug.print(“{}\n”, .{ void{} == undefined });
}
The following code prints true, but I’m not sure if it will always.
pub fn main() void {
@import(“std”).debug.print(“{}\n”, .{ void{} == undefined });
}
I think comparing something to undefined should be considered an error. Maybe a compiler-enforced one, but not something code should be doing in any case.
Yes, I agree it has no practice meaningfulness. It is just a theory problem. ![]()
For zero-bit types like void, the literal undefined is actually exactly equivalent to writing the single value of that type, at least right now (so yes, that comparison is always true right now). This is occasionally useful in generic code (e.g. ArrayHashMap uses it to initialize zero-bit “context” types implicitly IIRC), but please avoid using it unnecessarily: it’s much less readable than writing a concrete value like {}!
By the way, it’s planned to remove the syntax void{} in favour of the canonical spelling {}, so I suggest preferring the latter to avoid a migration job later ![]()