E4221#
Compiler diagnostic name: control_in_with_pattern_default.
A default expression in an or-pattern's with clause attempts to transfer
control with return, break, continue, or raise. The default must produce
a value locally and cannot leave its surrounding pattern.
Erroneous example#
///|
pub fn value_or_zero(value : Int?) -> Int {
match value {
Some(x) | (None with x = { return 0 }) => x
}
}
Suggestion#
Use a plain value as the default and perform any control flow after the pattern has matched.
///|
pub fn value_or_zero(value : Int?) -> Int {
match value {
Some(x) | (None with x = 0) => x
}
}