Skip to content

Runtime Reflection

Types annotated with @reflect carry a lightweight metadata table at runtime. Passing an instance to typeinfo() returns the same field descriptor as the comptime form, but resolved on a live value — useful for generic serializers and debuggers that must work without knowing the type at compile time.

Annotate a User struct with @reflect, then call typeinfo(u) on a live instance to read its name and field type at runtime.

02-runtime-reflect.zolo
Playground
// Feature: opt into runtime reflection with `@reflect`, then call

// `typeinfo(value)` to inspect an instance's type while the program runs.

// Types without `@reflect` carry no metadata (zero cost).


@reflect
struct User { id: int, name: str }

let u = User.new(7, "ada")
let info = typeinfo(u)
print(info.name)
// expected: User

print(info.fields[1].type_name)
// expected: str

enespt-br