T?, a shorthand for T | null.
Any type can be made nullable: primitive types, structures, and other composites.
null cannot be assigned to a non-nullable type.
Null safety
The compiler enforces null safety: nullable values cannot be accessed without an explicit null check.value == null is required before:
null, its type must be specified:
Smart casts
After a null check, the compiler automatically narrows the type. This feature is known as “smart casts”. It exists in TypeScript and Kotlin, and makes working with nullable types more natural. Examples:int? but initialized with a number, it’s a safe non-null integer:
null, meaning it can be safely passed to any nullable type:
Operator ! (non-null assertion)
The ! operator in Tolk is similar to ! in TypeScript and !! in Kotlin.
It allows bypassing the compiler’s check:
! operator is the only way to drop nullability from globals:
! is useful when non-nullability is guaranteed by conditions outside the code itself.
Stack layout and serialization
Atomics likeint? or cell? / etc. are backed by either TVM NULL or a value. Non-atomics are tagged unions.
Serialized as: null -> ‘0’, otherwise -> ‘1’+T, but address? is serialized specially.
For details, follow TVM representation and Serialization.