E3018#
Bounds of range pattern must be constant, named constant or wildcard.
Erroneous example#
///|
fn describe(value : Int, limit : Int) -> String {
match value {
0..<limit => "between"
_ => "outside"
}
}
///|
test {
inspect(describe(0, 3), content="between")
}
Suggestion#
You can either lift the variable a to a named constant:
///|
const A = 3
///|
fn describe(value : Int) -> String {
match value {
0..<A => "between"
_ => "outside"
}
}
///|
test {
inspect(describe(0), content="between")
}
Or, you can use the constant value directly:
///|
fn describe_literal(value : Int) -> String {
match value {
0..<3 => "between"
_ => "outside"
}
}
///|
test {
inspect(describe_literal(0), content="between")
}
Or, you can use a wildcard:
///|
fn describe_wildcard(value : Int) -> String {
match value {
0..<_ => "non-negative"
_ => "negative"
}
}
///|
test {
inspect(describe_wildcard(0), content="non-negative")
}
Notice, using wildcard alters the meaning of this range pattern.