Operator priority
From highest to lowest.Parenthesis ( )
Groups expressions: (1 + 2) * 3; or creates tensors: pair = (1, 2).
Square brackets [ ]
Creates typed tuples: [1, 2].
Operator lazy
With lazy loading the compiler loads only the accessed fields and skips the rest.
Non-null assertion operator !
Skips the nullability check: someVar!.
Unary operators ! ~ - +
Logical negation !x, bitwise not ~x, unary -x and +x.
Operators as is !is
Unsafe as cast and checks for union types: someVar is int.
Multiplicative * / % ^/ ~/
Integer multiplication, division, modulo, ceiling-division, and rounding-division. All integers have 257-bit precision.
Additive + -
Standard integer addition and subtraction.
Shifts << >> ^>> ~>>
Bitwise shifts, extended by ceiling-right and rounding-right.
Comparison == < > <= >= != <=>
Comparison operators. <=> is known as the spaceship or sign operator. Operators == and != also work for several non-numeric types. For example, addresses.
Bitwise & | ^
Standard bitwise operators, applicable to both integers and booleans.
Logical && ||
Short-circuit: the right operand is evaluated only when necessary.
Assignment = += -= and other
Assignment and augmented assignments.
Ternary ... ? ... : ...
Ternary expressions are available in conditions.
Missing operators
Tolk does not supporti++ and i--. Use i += 1 and i -= 1 instead.
Warnings on unexpected precedence
A common pitfall:flags & (0xFF != 0), because != has higher precedence, as in C++.
To prevent such cases, the compiler reports an error: