From 8a5dc9c22dbd0bfc1907754b440179a01bc82524 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 29 Nov 2023 18:28:50 -0800 Subject: [PATCH] [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. --- naga/src/front/wgsl/error.rs | 6 +++--- naga/tests/wgsl_errors.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/naga/src/front/wgsl/error.rs b/naga/src/front/wgsl/error.rs index dc10124680..f2db433e81 100644 --- a/naga/src/front/wgsl/error.rs +++ b/naga/src/front/wgsl/error.rs @@ -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(), ) diff --git a/naga/tests/wgsl_errors.rs b/naga/tests/wgsl_errors.rs index 56ca313464..a9f5e08fb4 100644 --- a/naga/tests/wgsl_errors.rs +++ b/naga/tests/wgsl_errors.rs @@ -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 = array(i); + } + ", + r###"error: automatic conversions cannot convert `i32` to `f32` + ┌─ wgsl:4:36 + │ +4 │ var a: array = array(i); + │ ^^^^^^^^^^^^^^^^ a value of type f32 is required here + +"###, + ) +} + #[test] fn binding_array_local() { check_validation! {