E3019

E3019 — A match arm whose integer literal cannot be represented in the scrutinee's type. The arm can never be selected, so the program does not mean what it says. Codegen used to parse the literal with a zero fallback, which turned an unrepresentable arm into a comparison against 0 — so the arm fired for scrutinee 0, the most common value there is, with no diagnostic.

What the compiler reports

E3019 … match arm literal '99999999999999999999' … not representable in the scrutinee's type 'i32' … can never be selected

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 match arm whose literal cannot be represented in the scrutinee's type can
// never be selected, so the program does not mean what it says.
//
// Codegen parsed the literal with a zero fallback, which turned the arm into a
// comparison against 0 -- so it fired for scrutinee 0, the most common value
// there is, and this program printed 777 with no diagnostic.
//
// The range is the scrutinee's, not a fixed width: the same literal against an
// i64 or i128 scrutinee is a different question, which is why the check reads
// the type rather than assuming one.
//

fn main() -> i32 {
  let n = 0;
  match n {
    99999999999999999999 => {
      print(777);
    }
    _ => {
      print(1);
    }
  }
  return 0;
}

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

Related