E4134#
此匿名函数的返回类型期望包含错误类型。请将错误类型添加到返回类型注释或改用 fn!
。
错误示例#
fn main {
let draw : (Int) -> Int! = fn(luck : Int) -> Int {
// ^~~
// Error: The return type of this anonymous function is expected include an
// error type. Please add the error type to the return type annotation or
// use `fn!` instead.
if luck == 7 {
return 42
}
fail!("Bad luck") // E4122 as well
}
try {
println("Draw: \{draw!(7)}")
} catch {
error => println("Error: \{error}")
}
}
建议#
将错误类型添加到返回类型注释:
fn main {
let draw : (Int) -> Int! = fn(luck : Int) -> Int! {
if luck == 7 {
return 42
}
fail!("Bad luck")
}
try {
println("Draw: \{draw!(7)}")
} catch {
error => println("Error: \{error}")
}
}