blob: c93bbf8d20eb82aba8a33cb3bff089deddbf0037 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
const std = @import("std");
const builtin = @import("builtin");
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" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
default_foo = get_foo() catch null; // This Line
try std.testing.expect(!default_foo.?.free);
}
|