I’m trying to declare a function that returns a struct within a test
block, but I’m getting an error.
Example:
test {
const Foo = struct {
pub fn init() Foo {
return .{};
}
}
const foo = Foo.init();
_ = foo;
}
And this is the error I get:
test.zig:19:23: error: use of undeclared identifier 'Foo'
pub fn init() Foo {
^~~
This behavior is the same with methods, e.g.:
test {
const Foo = struct {
pub fn bar(self: Foo) void {
_ = self;
}
}
const foo: Foo = .{};
foo.bar();
}
It seems I can’t reference a struct/namespace I declare in a test
block. Is this the intended behavior?