Sema: correct OPV for optional empty error set
prevents crashes in backends; improves codegen; provides more comptime-ness.
This commit is contained in:
13
test/cases/compile_errors/optional_empty_error_set.zig
Normal file
13
test/cases/compile_errors/optional_empty_error_set.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
export fn example() void {
|
||||
comptime foo() catch |err| switch (err) {};
|
||||
}
|
||||
var x: ?error{} = null;
|
||||
fn foo() !void {
|
||||
return x.?;
|
||||
}
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :6:13: error: unable to unwrap null
|
||||
// :2:17: note: called at comptime here
|
||||
22
test/cases/safety/optional_empty_error_set.zig
Normal file
22
test/cases/safety/optional_empty_error_set.zig
Normal file
@@ -0,0 +1,22 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, ra: ?usize) noreturn {
|
||||
_ = stack_trace;
|
||||
_ = ra;
|
||||
if (std.mem.eql(u8, message, "attempt to use null value")) {
|
||||
std.process.exit(0);
|
||||
}
|
||||
std.process.exit(1);
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
foo() catch |err| switch (err) {};
|
||||
return error.TestFailed;
|
||||
}
|
||||
var x: ?error{} = null;
|
||||
fn foo() !void {
|
||||
return x.?;
|
||||
}
|
||||
// run
|
||||
// backend=stage2,llvm
|
||||
// target=native
|
||||
Reference in New Issue
Block a user