Skip to content

Compile-Time Field Names

typeinfo(T) returns a compile-time descriptor of any declared type. Inside a comptime block you can iterate over .fields, reading .name and .type.kind to produce constants with zero runtime cost.

Read a Point struct's first field name and type kind from typeinfo at compile time — both print as constants, costing nothing at runtime.

01-comptime-field-names.zolo
Playground
// Feature: read a type's fields at compile time with `typeinfo(T)`.

// The descriptor is a record; access fields with `.name`, `.type.kind`, etc.

// When to use: generate code/data from a type's shape with zero runtime cost.


struct Point { x: int, y: int }

let first = comptime { typeinfo(Point).fields[0].name }
print(first)
// expected: x


let kind = comptime { typeinfo(Point).fields[0].type.kind }
print(kind)
// expected: int

enespt-br