An if can choose a value.
The short form fits on one line:
label = if ready then "ready" else "waiting"
The inline form also handles option capture:
label = if maybe_name is |name| then name else "guest"
Use block form when a branch needs more room:
label = if ready:
then "ready"
else
then "waiting"
;
Block form also inspects a present option:
label = if maybe_name is |name|:
then name
else
then "guest"
;
then provides the value for the surrounding assignment.
Both branches must provide the value or leave the function through another valid path.
When a condition is a known Bool, the same ordinary if can select one frontend-valid branch before HIR. Runtime conditions keep their normal behavior.
A value-producing if sends values to an immediate receiving site.
Inline form
label = if ready then "ready" else "waiting"
The inline then and else form stays on one logical line.
Inline option and choice predicates
The inline form also supports option-present capture and choice-variant predicates:
label = if maybe_name is |name| then name else "guest"
score = if status is Ready then 1 else 0
Block form
label = if ready:
then "ready"
else
then "waiting"
;
then sends one or more values from the active branch to the receiver.
The block form with then is supported at the same closed receiving sites as the inline form: declarations, assignments, multi-bind and returns.
Block option and choice predicates
The block form also supports option-present capture and choice-variant predicates:
label = if maybe_name is |name|:
then name
else
then "guest"
;
score = if status is Ready:
then 1
else
then 0
;
These are one-arm single-predicate value matches, not full if value is: matches. They require else.
Receiving sites
Value-producing control flow is accepted only at these closed receiving sites:
- declarations
- assignments
- multi-bind
- returns
It is not a general expression form. Nested then receivers are deferred.
A value-producing block is invalid directly inside:
- function arguments
- operator operands
- constructor arguments
- collection literals
- template interpolation
- expression statements
Completeness
- A value-producing
if requires else. - Every reachable branch must produce the required values or terminate.
- Mixed producing and terminating paths are complete.
- A real fallthrough path is rejected.
- At least one reachable branch must produce values.
- Every producing path must match the receiver's arity.
- Produced values must be compatible with the receiver's types.
Compile-time-known conditions
Both branches must satisfy normal completeness, receiving arity and type rules first. A known Bool then selects one validated branch, so no runtime branch or hidden merge value is needed. Runtime conditions retain the existing value-producing behavior.
label = if enabled:
then "on"
else
then "off"
;
The selected body keeps its child scope. Calls and other executable work from the inactive body do not reach generated materialisation, HIR or later analysis.
Option-present and choice-predicate inline and block forms use the same receiving-site model and are covered by the pattern references.