From 07b83ab6c0a19b2b355a3d76d5a47eea91a2ea11 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 29 Nov 2023 18:59:11 -0800 Subject: [PATCH] [naga wgsl-in] Use a better span for errors in constructors. When reporting errors in construction expressions, use the span of the constructor itself (that is, the type name) in preference to the span of the overall expression. This makes errors easier to follow. --- naga/src/front/wgsl/lower/construction.rs | 4 ++-- naga/tests/wgsl_errors.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/naga/src/front/wgsl/lower/construction.rs b/naga/src/front/wgsl/lower/construction.rs index c7e4106460..96cc45bfa5 100644 --- a/naga/src/front/wgsl/lower/construction.rs +++ b/naga/src/front/wgsl/lower/construction.rs @@ -448,7 +448,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { ctx.try_automatic_conversions_slice( &mut components, &Tr::Value(component_ty), - span, + ty_span, )?; expr = crate::Expression::Compose { ty, components }; } @@ -497,7 +497,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { // Array constructor, explicit type (components, Constructor::Type((ty, &crate::TypeInner::Array { base, .. }))) => { let mut components = components.into_components_vec(); - ctx.try_automatic_conversions_slice(&mut components, &Tr::Handle(base), span)?; + ctx.try_automatic_conversions_slice(&mut components, &Tr::Handle(base), ty_span)?; expr = crate::Expression::Compose { ty, components }; } diff --git a/naga/tests/wgsl_errors.rs b/naga/tests/wgsl_errors.rs index 56ca313464..b74f805f0d 100644 --- a/naga/tests/wgsl_errors.rs +++ b/naga/tests/wgsl_errors.rs @@ -213,9 +213,8 @@ fn constructor_parameter_type_mismatch() { ┌─ wgsl:3:21 │ 3 │ _ = mat2x2(array(0, 1), vec2(2, 3)); - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - │ │ │ - │ │ this expression has type array<{AbstractInt}, 2> + │ ^^^^^^^^^^^ ^^^^^^^^^^^ this expression has type array<{AbstractInt}, 2> + │ │ │ a value of type vec2 is required here "#,