Skip to content

Commit

Permalink
[naga wgsl-in] Drop spanless labels from front-end error messages.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimblandy committed Nov 30, 2023
1 parent 8da4925 commit 26f28e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ impl ParseError {
.with_labels(
self.labels
.iter()
.map(|label| {
Label::primary((), label.0.to_range().unwrap())
.filter_map(|label| label.0.to_range().map(|range| (label, range)))
.map(|(label, range)| {
Label::primary((), range)
.with_message(label.1.to_string())
})
.collect(),
Expand Down
19 changes: 19 additions & 0 deletions naga/tests/wgsl_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,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! {
Expand Down

0 comments on commit 26f28e3

Please sign in to comment.