Nitpick Casting System Specification

The Nitpick casting system relies entirely on explicit conversions. Implicit casting is not supported (e.g., passing an int64 to a function expecting int32 is a hard error without a cast). The language does not use the as keyword; instead, it uses specific syntax forms tailored for safety and code auditing.

1. The Three Casting Forms

Nitpick provides three ways to perform type casts. The first two are identical in semantics and both enforce safety checks (warnings), while the third is used to explicitly suppress warnings.

1.1 Infix Arrow Cast (=>)

The arrow operator provides a succinct, checked casting mechanism.

int64:large_val = 42i64;
int32:num = large_val => int32; 
flt32:f = large_val => flt32;

1.2 Checked Function-Style Cast (@cast<T>)

Functionally identical to =>. It exists for developers who prefer prefix notation or require explicit scoping in complex expressions.

int32:num = @cast<int32>(large_val);

1.3 Unchecked Function-Style Cast (@cast_unchecked<T>)

The unchecked cast performs the same low-level conversion but explicitly suppresses compiler warnings regarding data loss.

int8:byte = @cast_unchecked<int8>(large_val);

2. Compiler Warnings & Safety

Nitpick is designed to be noisy about potential data loss. When you use => or @cast<T>, the npkc compiler will emit warnings if the conversion is potentially destructive:

Resolving Warnings: If a narrowing or lossy cast is intentional, the developer MUST replace => or @cast<T> with @cast_unchecked<T>. This satisfies the compiler that the truncation has been audited.

3. Supported Types

Casting is strictly restricted to: * Numeric Types: int8, int16, int32, int64, flt32, flt64, uint8, etc. * Pointer Types: Struct pointers (MyStruct->), scalar pointers (int32->).

Note on Pointers: You can cast one pointer type to another, but you cannot cast integers (e.g., int64) directly to pointers using these operators. The compiler will reject it with the error: @cast supports numeric types and pointer types only. If you need to manage raw memory handles or opaque C pointers via FFI, it is highly recommended to use int64 integers instead of attempting to cast numeric addresses to pointer types in Nitpick.

4. Legacy / Deprecated Forms

Some older documents (like the v1 programming manual) make reference to a force cast syntax (expr!!). This is invalid in the modern compiler and will result in a syntax/parsing error. Always use @cast_unchecked<T> instead.