[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 authored and Teodor Tanasoaia committed 2023-12-04 12:22:13 +01:00
1 parent 07b83ab6c0
commit 33339e46ce
2 files changed
+22 -3

No files matched your search

+3 -3
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(),
)
+19
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! {