E3018

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  = 3

///|
fn ( : ) ->  {
  match  {
    0..< => "between"
    _ => "outside"
  }
}

///|
test {
  ((0), ="between")
}

Or, you can use the constant value directly:

///|
fn ( : ) ->  {
  match  {
    0..<3 => "between"
    _ => "outside"
  }
}

///|
test {
  ((0), ="between")
}

Or, you can use a wildcard:

///|
fn ( : ) ->  {
  match  {
    0..<_ => "non-negative"
    _ => "negative"
  }
}

///|
test {
  ((0), ="non-negative")
}

Notice, using wildcard alters the meaning of this range pattern.