From 22d4f6381c724cbe928ad2f25f64bdffae64eaf1 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 19 Dec 2024 11:07:18 -0500 Subject: [PATCH] diag(naga): clarify `ImageStore` type mismatch cases --- naga/src/valid/function.rs | 43 +++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/naga/src/valid/function.rs b/naga/src/valid/function.rs index c695d65144..812a18de88 100644 --- a/naga/src/valid/function.rs +++ b/naga/src/valid/function.rs @@ -137,8 +137,17 @@ pub enum FunctionError { LastCaseFallTrough, #[error("The pointer {0:?} doesn't relate to a valid destination for a store")] InvalidStorePointer(Handle), - #[error("The value {0:?} can not be stored")] - InvalidStoreValue(Handle), + #[error("Image store texture parameter type mismatch")] + InvalidStoreTexture { + actual: Handle, + actual_ty: crate::TypeInner, + }, + #[error("Image store value parameter type mismatch")] + InvalidStoreValue { + actual: Handle, + actual_ty: crate::TypeInner, + expected_ty: crate::TypeInner, + }, #[error("The type of {value:?} doesn't match the type stored in {pointer:?}")] InvalidStoreTypes { pointer: Handle, @@ -962,8 +971,15 @@ impl super::Validator { let value_ty = context.resolve_type(value, &self.valid_expression_set)?; match *value_ty { Ti::Image { .. } | Ti::Sampler { .. } => { - return Err(FunctionError::InvalidStoreValue(value) - .with_span_handle(value, context.expressions)); + return Err(FunctionError::InvalidStoreTexture { + actual: value, + actual_ty: value_ty.clone(), + } + .with_span_context(( + context.expressions.get_span(value), + format!("this value is of type {value_ty:?}"), + )) + .with_span(span, "expects a texture argument")); } _ => {} } @@ -1110,9 +1126,22 @@ impl super::Validator { } }; - if *context.resolve_type(value, &self.valid_expression_set)? != value_ty { - return Err(FunctionError::InvalidStoreValue(value) - .with_span_handle(value, context.expressions)); + let actual_value_ty = + context.resolve_type(value, &self.valid_expression_set)?; + if actual_value_ty != &value_ty { + return Err(FunctionError::InvalidStoreValue { + actual: value, + actual_ty: actual_value_ty.clone(), + expected_ty: value_ty.clone(), + } + .with_span_context(( + context.expressions.get_span(value), + format!("this value is of type {actual_value_ty:?}"), + )) + .with_span( + span, + format!("expects a value argument of type {value_ty:?}"), + )); } } S::Call {