add regression test case. closes #3007

master
Andrew Kelley 2019-11-18 19:51:49 -05:00
parent 21aed86a4a
commit 828abe046f
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 24 additions and 0 deletions

View File

@ -32,6 +32,7 @@ comptime {
_ = @import("behavior/bugs/2346.zig");
_ = @import("behavior/bugs/2578.zig");
_ = @import("behavior/bugs/2692.zig");
_ = @import("behavior/bugs/3007.zig");
_ = @import("behavior/bugs/3046.zig");
_ = @import("behavior/bugs/3112.zig");
_ = @import("behavior/bugs/3367.zig");

View File

@ -0,0 +1,23 @@
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);
}