@typeInfo only returns pub declarations. This is the case even if called from the same file as the struct declaration, where non-pub would otherwise be accessible.
For what it’s worth, you can mostly avoid running into this problem if you follow the convention of making imported types into filestructs instead:
Instead of
// in 'board.zig' top level
pub const Board = struct {
width: f32,
height: f32,
has_hole: bool,
};
do this
// in 'Board.zig' top level
pub const Board = @This();
width: f32,
height: f32,
has_hole: bool,
then when you import it, import it directly as the type
const Board = @import("Board.zig"); // this equivalent to the old "board.Board"
// "board" now free to be a variable name
const board = Board.init(1.23, 4.56, false);
Thanks. Yes very true. Coming from other languages I am not used yet to “a file is a struct”.
edit: on the other side I like types to have uppercase names and files lowercase
I do agree, but I would rather not depend on file properties that aren’t universally semantic or supported. Same reason I don’t use spaces in filenames even though that is perfectly valid too.
File-structs cannot be used with tagged unions or generic functions. If you think about it, it’s rather anti-pattern because it limits free evolution of the codebase (and/or easy refactors).