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
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E3018An array literal whose elements are not scalars, or which is empty. An array literal lowers to
tensor.from_elements, whose element type must be a scalar, so [a, b] for tensors — placed or not — has nothing to lower to, and an empty literal has no element type to give it. Both used to be accepted by the checker (the element type silently stayed at its f32 default) and then crash codegen with an internal error rather than a diagnostic. See Vx#354.
E3036A static call to a method several traits supply, where no impl takes the argument types written. Reported instead of an ambiguity (E3035), because ambiguity is not what went wrong: the call named one thing and the arguments ruled every candidate out. The message lists the impls that do exist, which is the edit.