Skip to content

Commit

Permalink
diag(naga): clarify select built-in type mismatch messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler authored and cwfitzgerald committed Dec 20, 2024
1 parent 9ea464b commit 6c9f93b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
24 changes: 19 additions & 5 deletions naga/src/valid/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ pub enum ExpressionError {
rhs_expr: Handle<crate::Expression>,
rhs_type: crate::TypeInner,
},
#[error("Selecting is not possible")]
InvalidSelectTypes,
#[error("Expected selection argument types to match, but reject value of type {reject:?} does not match accept value of value {accept:?}")]
SelectValuesTypeMismatch {
accept: crate::TypeInner,
reject: crate::TypeInner,
},
#[error("Expected selection condition to be a boolean value, got {actual:?}")]
SelectConditionNotABool { actual: crate::TypeInner },
#[error("Relational argument {0:?} is not a boolean vector")]
InvalidBooleanVector(Handle<crate::Expression>),
#[error("Relational argument {0:?} is not a float")]
Expand Down Expand Up @@ -901,7 +906,8 @@ impl super::Validator {
} => {
let accept_inner = &resolver[accept];
let reject_inner = &resolver[reject];
let condition_good = match resolver[condition] {
let condition_ty = &resolver[condition];
let condition_good = match *condition_ty {
Ti::Scalar(Sc {
kind: Sk::Bool,
width: _,
Expand All @@ -928,8 +934,16 @@ impl super::Validator {
},
_ => false,
};
if !condition_good || accept_inner != reject_inner {
return Err(ExpressionError::InvalidSelectTypes);
if accept_inner != reject_inner {
return Err(ExpressionError::SelectValuesTypeMismatch {
accept: accept_inner.clone(),
reject: reject_inner.clone(),
});
}
if !condition_good {
return Err(ExpressionError::SelectConditionNotABool {
actual: condition_ty.clone(),
});
}
ShaderStages::all()
}
Expand Down
4 changes: 2 additions & 2 deletions naga/tests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ error: Entry point main at Compute is invalid
│ ^^^^^^ naga::Expression [3]
= Expression [3] is invalid
= Selecting is not possible
= Expected selection condition to be a boolean value, got Scalar(Scalar { kind: Sint, width: 4 })
",
),
Expand All @@ -670,7 +670,7 @@ error: Entry point main at Compute is invalid
│ ^^^^^^ naga::Expression [3]
= Expression [3] is invalid
= Selecting is not possible
= Expected selection argument types to match, but reject value of type Scalar(Scalar { kind: Bool, width: 1 }) does not match accept value of value Scalar(Scalar { kind: Sint, width: 4 })
",
),
Expand Down
2 changes: 1 addition & 1 deletion naga/tests/wgsl_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ fn select() {
naga::valid::ValidationError::Function {
name,
source: naga::valid::FunctionError::Expression {
source: naga::valid::ExpressionError::InvalidSelectTypes,
source: naga::valid::ExpressionError::SelectConditionNotABool { .. },
..
},
..
Expand Down

0 comments on commit 6c9f93b

Please sign in to comment.