Skip to content

Explicit Nullability (T?)

In Wysna, types are non-nullable by default. A variable of type str can never hold none. This eliminates the “billion-dollar mistake” and prevents unexpected null dereference crashes at runtime.

When a value may legitimately be absent, you must append ? to the type annotation. Absent values are represented by the literal keyword none:

# Non-nullable: guaranteed to contain a valid string
let user: str = "Alice"
# Nullable: can contain either a string or none
let nickname: str? = none

If you try to pass nickname into a function that expects str, the compiler rejects it:

Error: Type mismatch. Expected `str`, found `str?`

Use the ?? operator to provide a fallback default when an optional value is none:

fn get_display_name(username: str, nickname: str?) -> str {
# If nickname is none, evaluate to username
return nickname ?? username
}
fn main() -> unit {
print(get_display_name("washo", none)) # prints: washo
print(get_display_name("washo", "El Ingeniero")) # prints: El Ingeniero
}

To inspect an optional value and access its underlying payload, you can match on Some(v) and None:

fn process_optional(value: str?) -> unit {
match value {
Some(text) => {
print("Value length:", len(text))
},
None => {
print("Value was absent")
}
}
}