[naga wgsl-in] Drop spanless labels from front-end error messages.

When a label in a WGSL front end error has an undefined span, omit the
label from the error message. This is not great, but because of the
way Naga IR represents local variable references it is hard to get the
right span, and omitting the label better than panicking in `unwrap`,
since the error message has a general message anyway.
This commit is contained in:
Jim Blandy
2023-11-29 18:28:50 -08:00
committed by Teodor Tanasoaia
parent 07b83ab6c0
commit 33339e46ce
2 changed files with 22 additions and 3 deletions

View File

@@ -34,9 +34,9 @@ impl ParseError {
.with_labels(
self.labels
.iter()
.map(|label| {
Label::primary((), label.0.to_range().unwrap())
.with_message(label.1.to_string())
.filter_map(|label| label.0.to_range().map(|range| (label, range)))
.map(|(label, range)| {
Label::primary((), range).with_message(label.1.to_string())
})
.collect(),
)

View File

@@ -1984,6 +1984,25 @@ fn function_param_redefinition_as_local() {
)
}
#[test]
fn constructor_type_error_span() {
check(
"
fn unfortunate() {
var i: i32;
var a: array<f32, 1> = array<f32, 1>(i);
}
",
r###"error: automatic conversions cannot convert `i32` to `f32`
┌─ wgsl:4:36
4 │ var a: array<f32, 1> = array<f32, 1>(i);
│ ^^^^^^^^^^^^^^^^ a value of type f32 is required here
"###,
)
}
#[test]
fn binding_array_local() {
check_validation! {