Skip to content
Playground(another site)

bynk.types.range_pattern_on_non_int

Error A range pattern (lo..hi) was matched against a scrutinee that is not an Int.

A range pattern lo..hi matches an Int by comparing it with two bounds. It is not offered for a Float, because NaN is neither inside nor outside a range, nor for a String; both are left out on purpose. Compare with < and >= in an if instead. An empty range is bynk.types.empty_range_pattern.

Example

fn band(x: Float) -> String {
match x {
1..3 => "low" // ✗ a range pattern matches an `Int`
_ => "high"
}
}
fn band(x: Float) -> String {
if x < 3.0 { "low" } else { "high" } // ✓ compare in an `if`
}

In the Book

See also

  • The grammar rule it governs: int_range.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.range_pattern_on_non_int shows the same from the installed toolchain, without a network.