E3051
E3051 — Amatchpattern of another type than the value matched: a variant of another enum, such asOther::Redin amatchon aColor,truein amatchon ani32, or1in amatchon abool. 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
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E3050A pattern inside a variant's payload that is not a name or
_, such as the 3 in Val(3) or the Inner::A(v) in Wrap(Inner::A(v)). The compiler does not test such a pattern when it chooses an arm, so the arm would be taken for any payload. Bind the payload to a name and test it in the arm, with an if or another match.
E3052Arithmetic on fp8 or fp4 values (f8e4m3, f8e5m2 or f4e2m1) with no written result type, as in print(a * b). The compiler computes in f32 and rounds once to the written type, so the program must write it: let c : f32 = a * b;. Also += and the other compound operators on these values, and any operator on tensors of them.