2019-11-19 08:51:49 +08:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
const Foo = struct {
|
|
|
|
free: bool,
|
|
|
|
|
|
|
|
pub const FooError = error{NotFree};
|
|
|
|
};
|
|
|
|
|
|
|
|
var foo = Foo{ .free = true };
|
|
|
|
var default_foo: ?*Foo = null;
|
|
|
|
|
|
|
|
fn get_foo() Foo.FooError!*Foo {
|
|
|
|
if (foo.free) {
|
|
|
|
foo.free = false;
|
|
|
|
return &foo;
|
|
|
|
}
|
|
|
|
return error.NotFree;
|
|
|
|
}
|
|
|
|
|
|
|
|
test "fixed" {
|
|
|
|
default_foo = get_foo() catch null; // This Line
|
2021-05-05 02:23:22 +08:00
|
|
|
try std.testing.expect(!default_foo.?.free);
|
2019-11-19 08:51:49 +08:00
|
|
|
}
|