Fluid values are a special category of values that are not explicitly typed. They come in two kinds: integral and float. A fluid integral may implicitly convert to any builtin integral type, and a fluid float may implicitly convert to any builtin float type. Integer literals
are fluid integrals and float literals
are fluid floats.
In addition, the result of a operator where all operands are fluid is itself also fluid. The fluid kind of the result is the same as the operands. The use of parentheses are also supported.
1 2 3 4 5 6 7 8 9 10 11 12 13 14// valid const fluid_int_1: UInt = 12; const fluid_int_2: I32 = 2 * (5 + -1) + 4; const fluid_float_1: F32 = 12.4; const fluid_float_2: F64 = 3.0 + 9.0; // invalid becase `12` is fluid (and not explicitly typed), therefore the type cannot be inferred const fluid_int_3 = 12; // invalid because `12.4` is a fluid float, and cannot be implicitly converted to an integral type const fluid_int_4: Int = 12.4; // invalid because `12` is a fluid integral, and cannot be implicitly converted to a float type const fluid_float_3: F32 = 12;
def variables
that are implicitly typed and are declared with a fluid value are themselves fluid.
1 2 3 4 5 6 7// valid becase this `def` variable has no explicit type and therefore is fluid def NUM = 12; const num: Int = NUM; const num_2: Int = NUM + 14; // invalid because NUM is fluid (not explicitly typed), therefore the type cannot be inferred const num_3 = NUM;