-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.