Strange pub behavior

Hi guys,

Have look at the following code

fn foo() void {
    const item = struct {
        fn format(_: @This(), _: ?*std.Io.Writer) void {}
    };
    const a = item{};
    a.format(null); // A
    std.debug.print("{f}\n", .{a}); // B
}

A is always ok , B will eventually call a.format but required that format is pub . What makes the difference?

Because print is in a different file, so it can’t access format unless it is pub

2 Likes