Ah, if the function field is annotated with comptime, then it compiles.
const Foo = struct {
x: bool,
comptime y: u8 = 123,
comptime f: fn() void = bar, // compiles okay now
};
fn bar() void {}
pub fn main() !void {
var foo = Foo{.x = true};
foo.x = false;
}
I thought function fields are comptime implicitly before. So it looks this understanding is wrong.
I still haven’t got the reason why the code in the first comment fails to compile.