Generated functions must not mutate or observe any non-constant global state (including, for example, IO, locks, non-local dictionaries, or using hasmethod).
you’re fine I think, you’re not mutating any non-constant global state, and I don’t think fieldcount(T) is a mutable global state.
technically fieldcount is a generic function which could be overloaded for a specific type.
But if that happens a lot of other things will probably break,
so you are already in hell.
This code is fine basically.
Also check ConstructionBase.jl: it has getfields(your_obj) and getproperties(your_obj).
It’s a very lightweight package, a large fraction of Julia ecosystem depends on it.