E3051

E3051 — A match pattern of another type than the value matched: a variant of another enum, such as Other::Red in a match on a Color, true in a match on an i32, or 1 in a match on a bool. Write a pattern of the matched value's type.

What the compiler reports

Error[E3051] at {{.*}}a_float_arm_in_a_match_on_an_integer.vx:[[@LINE+1]]:5: `1.5` is a float, but the value matched has the type `i32`{{$}}
1 error(s) emitted

The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.

A program that triggers it

//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// A float arm in a `match` on an integer is an error. Such a program used to stop the compiler.
//

fn pick(x : i32) -> i32 {
  let mut found = 0;
  match x {
    1.5 => {
      found = 1;
    }
    _ => {
      found = 0;
    }
  }
  return found;
}

fn main() -> i32 {
  print(pick(1));
  return 0;
}

From tests/frontend/fail/a_float_arm_in_a_match_on_an_integer.vx, which asserts this diagnostic on every commit.

Related