-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as not planned
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.
Description
Zig Version
0.14.0-dev.1924+bdd3bc056
Steps to Reproduce and Observed Behavior
fn b(arg: ?bool) bool {
return if (arg) true else false;
}
fn u(arg: ?u0) bool {
return if (arg) true else false;
}
test {
_ = comptime b(true); //passes (yields false)
_ = comptime u(0); //passes (yields false)
//_ = b(true); //correctly issues compile error `expected type 'bool', found '?bool'`
//_ = u(0); //correctly issues compile error `expected type 'bool', found '?u0'`
}Expected Behavior
Optional-unwrapping if should always require a capture, as it does in runtime code.
IMO this should count as a miscompilation, since invalid code (where the intent is not clear) is processed (and yields an unintuitive result).
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.