CLS enums are literals with identity — they differ fundamentally from type-alias unions. ADocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt
Use this file to discover all available pages before exploring further.
alias Color = "red" | "green" is a compile-time annotation that dissolves at runtime; no runtime value ever is a Color. An enum Color { Rojo, Verde, Azul } creates real runtime values where each variant carries its definition name, its variant name, and its numeric index within the enum. Because of this identity, enums support equality checks, membership tests (is), and iteration — making them ideal for state machines, protocol tags, and embedded targets where you want descriptive names that compile down to 1–2 bytes.
Declaration
Declare an enum with theenum keyword, a name, and a comma-separated list of variant names inside braces. A trailing comma after the last variant is allowed.
PascalCase.
Accessing variants
Variants are accessed via the enum name as a namespace separator:Comparison
Use== to compare two enum values. Equality is checked by identity (definition name + variant index), so variants from different enums are never equal even if they have the same name.
The is operator
The is operator tests whether a value belongs to a specific enum definition. This is useful for runtime type guards, especially when a function can receive values from multiple enum types.
Iteration
Enums are iterable.for each visits every variant in declaration order:
Iteration with index
Addand <name> to receive the zero-based variant index alongside each value:
u8/u16 in a native binary.
Type annotation
In strict mode the type checker accepts the enum name as a type annotation. Assigning a non-enum value raises a type error.var c: Color = Estado.Apagado; is an error).
Enums in switch / case
Because enum variants compare by equality, they work naturally asswitch patterns:
Runtime representation
At runtime the interpreter maintains two value kinds for enums:| Value kind | Contents | Purpose |
|---|---|---|
Value::EnumDef | Name + ordered list of variant strings | The enum definition itself — stored as a variable |
Value::Enum | { def_name, variant, index } | A concrete variant value |
index field is the zero-based position of the variant in the declaration. When targeting a native binary, the index is emitted as a u8 (0–255 variants) or u16 (up to 65 535 variants) — far cheaper than heap-allocated strings.
Exporting enums
Prefix the declaration withexport to make the enum available to other modules that import the file:
Enums vs type-alias unions
| Feature | enum | alias union |
|---|---|---|
| Runtime identity | ✅ real value | ❌ erased at runtime |
Equality (==) | ✅ by identity | String/literal equality only |
is membership test | ✅ | ❌ |
| Iteration | ✅ | ❌ |
| Compile target size | 1–2 bytes | varies (string length) |
| Type-checker narrowing | ✅ | ✅ |
enum when you need runtime behaviour (switching, iteration, membership checks). Use alias when you only need the type checker to validate that a string or number belongs to a known set.
Enum variants currently carry no associated payload (no data attached to a
specific variant). Pattern matching with per-variant data is planned as a
future language feature. For now, pair an enum with a record or structure if
you need variant-specific data.
Full enum test example
Full enum test example
The following is drawn directly from
examples/tests/test-enums.clsx: