void and never, similar to TypeScript. Both represent the absence of a value, but in different ways.
A function that returns nothing is void
Both functions below return void:
return statements.
A return without a value means “void”.
Explicitly specifying fun(...): void behaves identically:
In some languages, an empty value is called “unit”, and a function that returns nothing, actually returns “unit”.
In Tolk, “void” is used for that, like in TypeScript.
But to some extent, they are equivalent.
Special fields with void type
If a structure field is void, it indicates that the field does not exist at all.
<T = void>, allowing structures to express optional or missing fields.
A function that never returns is never
An always-throwing function is an example:
match expression, branches that never return are also of type never:
Implicit never in unreachable conditions
The never type occurs implicitly when a condition is impossible to satisfy.
More precisely, it means that no value of such a type can exist; no possible data can produce such a value:
null:
never in a compilation error typically indicates an issue in the preceding code.
Stack layout and serialization
Both mean “absence of a value” and occupy zero stack slots and zero bits. For example, avoid function does not place any value onto the stack.
For details, follow TVM representation and Serialization.