Skip to content

Commit 6d6a99f

Browse files
WIP: diag(naga): refine spans for Select type errors
TODO: This is an improvement. Are there further improvements to make? TODO: Would these errors look fine with the "overall" span still intact?
1 parent ed0965d commit 6d6a99f

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

naga/src/valid/expression.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,18 @@ pub enum ExpressionError {
5454
rhs_expr: Handle<crate::Expression>,
5555
rhs_type: crate::TypeInner,
5656
},
57-
#[error("Expected selection argument types to match, but reject value of type {reject:?} does not match accept value of value {accept:?}")]
57+
#[error("Expected selection reject and accept values ({accept:?} and {reject:?}, respectively) to match, but they have different types")]
5858
SelectValuesTypeMismatch {
59-
accept: crate::TypeInner,
60-
reject: crate::TypeInner,
59+
accept: Handle<crate::Expression>,
60+
accept_ty: crate::TypeInner,
61+
reject: Handle<crate::Expression>,
62+
reject_ty: crate::TypeInner,
63+
},
64+
#[error("Expected selection condition {actual:?} to be a boolean value")]
65+
SelectConditionNotABool {
66+
actual: Handle<crate::Expression>,
67+
actual_ty: crate::TypeInner,
6168
},
62-
#[error("Expected selection condition to be a boolean value, got {actual:?}")]
63-
SelectConditionNotABool { actual: crate::TypeInner },
6469
#[error("Relational argument {0:?} is not a boolean vector")]
6570
InvalidBooleanVector(Handle<crate::Expression>),
6671
#[error("Relational argument {0:?} is not a float")]
@@ -160,8 +165,21 @@ impl ExpressionError {
160165
Self::IndexableLength(..) => Vec::new(),
161166
Self::InvalidUnaryOperandType(..) => Vec::new(),
162167
Self::InvalidBinaryOperandTypes { .. } => Vec::new(),
163-
Self::SelectValuesTypeMismatch { .. } => Vec::new(),
164-
Self::SelectConditionNotABool { .. } => Vec::new(),
168+
Self::SelectValuesTypeMismatch {
169+
accept,
170+
ref accept_ty,
171+
reject,
172+
ref reject_ty,
173+
} => vec![
174+
(accept, format!("accept value of type {accept_ty:?}")),
175+
(reject, format!("reject value of type {reject_ty:?}")),
176+
],
177+
Self::SelectConditionNotABool {
178+
actual,
179+
ref actual_ty,
180+
} => {
181+
vec![(actual, format!("this is of type {actual_ty:?}"))]
182+
}
165183
Self::InvalidBooleanVector(..) => Vec::new(),
166184
Self::InvalidFloatArgument(..) => Vec::new(),
167185
Self::Type(..) => Vec::new(),
@@ -1018,13 +1036,16 @@ impl super::Validator {
10181036
};
10191037
if accept_inner != reject_inner {
10201038
return Err(ExpressionError::SelectValuesTypeMismatch {
1021-
accept: accept_inner.clone(),
1022-
reject: reject_inner.clone(),
1039+
accept,
1040+
accept_ty: accept_inner.clone(),
1041+
reject,
1042+
reject_ty: reject_inner.clone(),
10231043
});
10241044
}
10251045
if !condition_good {
10261046
return Err(ExpressionError::SelectConditionNotABool {
1027-
actual: condition_ty.clone(),
1047+
actual: condition,
1048+
actual_ty: condition_ty.clone(),
10281049
});
10291050
}
10301051
ShaderStages::all()

0 commit comments

Comments
 (0)