-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Design
T? is a built-in first-class optional type — same relationship as E!T to Result[E, T]. It is not sugar over a generic Option[T].
fn find(id: Int) User?
let user: User? = find(42)
let name = user orelse "unknown"
Unwrapping
orelse— provide a default:x orelse fallbackwhen— pattern match:when x { value(v) => ..., null => ... }
Rules
nullliteral is only valid where aT?type is expected — no untyped nullTwidens toT?automatically (non-null is always a valid optional)- Assigning
T?whereTis expected is a type error — must unwrap explicitly
Implementation notes
Mirrors the E!T system:
PipeTypeAnnotation: addoptional: *PipeTypeAnnotationPipeType: addoptional: *PipeType- Parser: postfix
?on type annotations;orelseinfix expression - Type checker: enforce null only in optional positions; track unwrap
- Interpreter:
Value.nullalready exists, just needs type gating
Timing
Add after generics are settled — T? being built-in avoids the T? vs Option[T] design knot entirely, same as E!T vs Result[E, T]. Safe to defer as long as no null literal is exposed in the syntax before this lands.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request