The function returns T!, so ? must produce an error, but a missing optional value carries
no error message. Say what the error is with else fail("...").
Wrong#
fn head(xs: [int]): int! {
let x = xs.first()?
x
}Fixed#
fn head(xs: [int]): int! {
let x = xs.first() else fail("empty list")
x
}Common causes#
find,get,first,env.getreturnT?: give the missing case a message.- Return
T?from the function instead if "missing" is all callers need.