Null, omission, and return types¶
Nullability, omitted arguments, unfinished implementations, and the absence of a return value express different contracts. They are not interchangeable.
Design documentation
This chapter describes the language design. Examples are illustrative; implementation availability and unresolved rules are explained in Design status.
Distinct roles¶
| Construct | Purpose |
|---|---|
null |
Explicitly permitted absence |
| Parameter sentinel | Distinguish omission from a supplied argument |
... |
An unfinished-body marker or a separately specified ellipsis value |
void |
Normal completion without a result |
NoReturn |
No normal return is possible |
These have distinct roles:
nullis available for any base type only when explicitly permitted.- Ellipsis is accepted by the compiler as an argument regardless of base type, requires no opt-in annotation, and is truthy.
- A sentinel is a parameter-scoped omission marker, not an ordinary transferable value of the annotated type.
voidmeans no result.NoReturnmeans a function cannot complete by returning normally.
fun add(x: null mut int, y: int) -> int { ... }
fun configure(limit: int = omitted) {
if limit is omitted {
...
}
}
The first argument to add permits null and mutation; y permits neither. A
function accepting mut arguments cannot be pure. Sentinel names and syntax are
provisional. Each sentinel belongs to its parameter scope, may be checked, and
cannot be passed on, returned, or stored as an ordinary value.
Unfinished code and ellipsis values¶
Standalone ... marks unfinished implementation and raises NotImplementedError
in development/test execution. That use is prohibited in production builds.
Passing, forwarding, and inspecting an ellipsis value is a separate capability.
Open: the final interaction between universally admissible ellipsis values,
operations requiring concrete data, and the production ban on unfinished-code
failures. A proposed rule was to raise NotImplementedError on concrete use, but
this needs reconciliation with the later production restriction. Ellipsis must
not silently become permission to ship unimplemented bodies.