Zig Version
0.12.0-dev.47+0461a64a9
Steps to Reproduce and Observed Behavior
fn foo(x: bool) error{OutOfMemory}![]const u8 {
if (x) return "" else return error.OutOfMemory;
}
test {
var x = true;
const val = foo(x) catch |err| switch (err) {
error.OutOfMemory => null,
};
_ = val;
}
~ % zig test test.zig
test.zig:7:36: error: value with comptime-only type '@TypeOf(null)' depends on runtime control flow
const val = foo(x) catch |err| switch (err) {
^~~~~~
test.zig:7:24: note: runtime control flow here
const val = foo(x) catch |err| switch (err) {
~~~~~~~^~~~~
Giving val an explicit type of ?[]const u8 prevents the error
Expected Behavior
Test passes
Zig Version
0.12.0-dev.47+0461a64a9
Steps to Reproduce and Observed Behavior
Giving
valan explicit type of?[]const u8prevents the errorExpected Behavior
Test passes