dok/spec/flow-typing
Dok supports flow typing, i.e. if a variable is tested for being of a specific type, then in the rest of the code block, it is assumed of this type without a reassignation.
fun f(x::Int?)::Int {
when x.isa(Int) {
return x + 1
#-NOTE `x` has type `Int` now
} -else {
return 0
}
}
assert f(0) == 1
assert f(Null) == 0