Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diag(naga): clarify ImageStore type mismatch cases #6791

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions naga/src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,17 @@ pub enum FunctionError {
LastCaseFallTrough,
#[error("The pointer {0:?} doesn't relate to a valid destination for a store")]
InvalidStorePointer(Handle<crate::Expression>),
#[error("The value {0:?} can not be stored")]
InvalidStoreValue(Handle<crate::Expression>),
#[error("Image store texture parameter type mismatch")]
InvalidStoreTexture {
actual: Handle<crate::Expression>,
actual_ty: crate::TypeInner,
},
#[error("Image store value parameter type mismatch")]
InvalidStoreValue {
actual: Handle<crate::Expression>,
actual_ty: crate::TypeInner,
expected_ty: crate::TypeInner,
},
#[error("The type of {value:?} doesn't match the type stored in {pointer:?}")]
InvalidStoreTypes {
pointer: Handle<crate::Expression>,
Expand Down Expand Up @@ -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"));
}
_ => {}
}
Expand Down Expand Up @@ -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 {
Expand Down