Skip to content

Commit 89a11f3

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 61fd166 commit 89a11f3

2 files changed

Lines changed: 39 additions & 16 deletions

File tree

naga/src/valid/expression.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,18 @@ pub enum ExpressionError {
5353
rhs_expr: Handle<crate::Expression>,
5454
rhs_type: crate::TypeInner,
5555
},
56-
#[error("Expected selection argument types to match, but reject value of type {reject:?} does not match accept value of value {accept:?}")]
56+
#[error("Expected selection reject and accept values ({accept:?} and {reject:?}, respectively) to match, but they have different types")]
5757
SelectValuesTypeMismatch {
58-
accept: crate::TypeInner,
59-
reject: crate::TypeInner,
58+
accept: Handle<crate::Expression>,
59+
accept_ty: crate::TypeInner,
60+
reject: Handle<crate::Expression>,
61+
reject_ty: crate::TypeInner,
62+
},
63+
#[error("Expected selection condition {actual:?} to be a boolean value")]
64+
SelectConditionNotABool {
65+
actual: Handle<crate::Expression>,
66+
actual_ty: crate::TypeInner,
6067
},
61-
#[error("Expected selection condition to be a boolean value, got {actual:?}")]
62-
SelectConditionNotABool { actual: crate::TypeInner },
6368
#[error("Relational argument {0:?} is not a boolean vector")]
6469
InvalidBooleanVector(Handle<crate::Expression>),
6570
#[error("Relational argument {0:?} is not a float")]
@@ -159,8 +164,21 @@ impl ExpressionError {
159164
Self::IndexableLength(..) => Vec::new(),
160165
Self::InvalidUnaryOperandType(..) => Vec::new(),
161166
Self::InvalidBinaryOperandTypes { .. } => Vec::new(),
162-
Self::SelectValuesTypeMismatch { .. } => Vec::new(),
163-
Self::SelectConditionNotABool { .. } => Vec::new(),
167+
Self::SelectValuesTypeMismatch {
168+
accept,
169+
ref accept_ty,
170+
reject,
171+
ref reject_ty,
172+
} => vec![
173+
(accept, format!("accept value of type {accept_ty:?}")),
174+
(reject, format!("reject value of type {reject_ty:?}")),
175+
],
176+
Self::SelectConditionNotABool {
177+
actual,
178+
ref actual_ty,
179+
} => {
180+
vec![(actual, format!("this is of type {actual_ty:?}"))]
181+
}
164182
Self::InvalidBooleanVector(..) => Vec::new(),
165183
Self::InvalidFloatArgument(..) => Vec::new(),
166184
Self::Type(..) => Vec::new(),
@@ -1007,13 +1025,16 @@ impl super::Validator {
10071025
};
10081026
if accept_inner != reject_inner {
10091027
return Err(ExpressionError::SelectValuesTypeMismatch {
1010-
accept: accept_inner.clone(),
1011-
reject: reject_inner.clone(),
1028+
accept,
1029+
accept_ty: accept_inner.clone(),
1030+
reject,
1031+
reject_ty: reject_inner.clone(),
10121032
});
10131033
}
10141034
if !condition_good {
10151035
return Err(ExpressionError::SelectConditionNotABool {
1016-
actual: condition_ty.clone(),
1036+
actual: condition,
1037+
actual_ty: condition_ty.clone(),
10171038
});
10181039
}
10191040
ShaderStages::all()

naga/tests/validation.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,13 @@ fn main() {
644644
",
645645
"\
646646
error: Entry point main at Compute is invalid
647-
┌─ wgsl:4:9
647+
┌─ wgsl:4:22
648648
649649
4 │ _ = select(1, 2, 9001);
650-
│ ^^^^^^^^^^^^^^^^^^ naga::ir::Expression [3]
650+
^^^^ this is of type Scalar(Scalar { kind: Sint, width: 4 })
651651
652652
= Expression [3] is invalid
653-
= Expected selection condition to be a boolean value, got Scalar(Scalar { kind: Sint, width: 4 })
653+
= Expected selection condition [2] to be a boolean value
654654
655655
",
656656
),
@@ -664,13 +664,15 @@ fn main() {
664664
",
665665
"\
666666
error: Entry point main at Compute is invalid
667-
┌─ wgsl:4:9
667+
┌─ wgsl:4:16
668668
669669
4 │ _ = select(true, 1, false);
670-
│ ^^^^^^^^^^^^^^^^^^^^^^ naga::ir::Expression [3]
670+
│ ^^^^ ^ accept value of type Scalar(Scalar { kind: Sint, width: 4 })
671+
│ │
672+
│ reject value of type Scalar(Scalar { kind: Bool, width: 1 })
671673
672674
= Expression [3] is invalid
673-
= 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 })
675+
= Expected selection reject and accept values ([1] and [0], respectively) to match, but they have different types
674676
675677
",
676678
),

0 commit comments

Comments
 (0)