Defining function type in tuple type directly cuasing syntax error

const Foo = []const struct { fn () void };

Errors: expected ‘;’ or block after function prototype

But if we do something like this:

const FooFn = fn () void;
const Foo = []const struct { FooFn };

It compiles properly.

Is this expected? Or there is some syntax parsing issue with it?

Zig version 0.16.0

The parser assumes that when it encounters a fn directly inside a struct it must be a declaration.

Any syntax that semantically gets between the fn and the struct works. You found one way to do that, but just wrapping it in () also works.

3 Likes