mirror of
https://github.com/ziglang/zig.git
synced 2026-01-13 19:05:12 +00:00
And fix test cases to make them pass. This is in preparation for starting to pass behavior tests with self-hosted.
24 lines
425 B
Zig
24 lines
425 B
Zig
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
|
|
std.testing.expect(!default_foo.?.free);
|
|
}
|