Nullability and Type Checking
Kelvra is strictly typed by default. The repo has broad type-error coverage, and the docs should reflect that posture instead of softening it.
Nullable types
Section titled “Nullable types”Nullable types are written with ?.
var maybeScore i32? = 7if (maybeScore != null) { print("score present")}You can also assign null later:
type Dog struct { fn bark() str { return "woof" }}
var maybeDog Dog? = Dog()maybeDog = nullExplicit null checks
Section titled “Explicit null checks”The current type checker expects explicit checks before optional member access or optional calls. The repo includes negative tests for both.
if (maybeDog != null) { print("dog present")}Assignment rules
Section titled “Assignment rules”The type checker already rejects:
- assigning
nullto non-optional bindings - assigning the wrong primitive or collection type
- assigning to
const - invalid subtype assignments
- invalid handle/package-type mixing
Function checking
Section titled “Function checking”Functions are checked for:
- argument type mismatches
- lambda parameter and return mismatches
- invalid casts
- wrong return types
- missing values on non-
voidreturns
Control-flow checking
Section titled “Control-flow checking”The repo also enforces loop-control correctness:
breakoutside loops is rejectedcontinueoutside loops is rejected- unknown loop labels are rejected
- duplicate loop labels are rejected
Imports and types
Section titled “Imports and types”Typed imports are checked too. Existing tests cover:
- missing imported symbols
- typed import binding mismatches
- native package binding mismatches
- import cycles surfaced during frontend analysis