mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Properly recognize Literal expressions as non-dynamic indices. (#2537)
Restore `negative_index` test in `tests/wgsl-errors.rs`, as part of the `invalid_arrays` test function.
This commit is contained in:
committed by
Teodor Tanasoaia
parent
c5b2afaf78
commit
ca2e810492
@@ -466,11 +466,13 @@ impl crate::Expression {
|
||||
/// [`Access`]: crate::Expression::Access
|
||||
/// [`ResolveContext`]: crate::proc::ResolveContext
|
||||
pub fn is_dynamic_index(&self, module: &crate::Module) -> bool {
|
||||
if let Self::Constant(handle) = *self {
|
||||
let constant = &module.constants[handle];
|
||||
!matches!(constant.r#override, crate::Override::None)
|
||||
} else {
|
||||
true
|
||||
match *self {
|
||||
Self::Literal(_) | Self::ZeroValue(_) => false,
|
||||
Self::Constant(handle) => {
|
||||
let constant = &module.constants[handle];
|
||||
!matches!(constant.r#override, crate::Override::None)
|
||||
}
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,25 +107,6 @@ fn unknown_identifier() {
|
||||
);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn negative_index() {
|
||||
// check(
|
||||
// r#"
|
||||
// fn main() -> f32 {
|
||||
// let a = array<f32, 3>(0., 1., 2.);
|
||||
// return a[-1];
|
||||
// }
|
||||
// "#,
|
||||
// r#"error: expected unsigned integer constant expression, found `-1`
|
||||
// ┌─ wgsl:4:26
|
||||
// │
|
||||
// 4 │ return a[-1];
|
||||
// │ ^^ expected unsigned integer
|
||||
|
||||
// "#,
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn bad_texture() {
|
||||
check(
|
||||
@@ -921,6 +902,26 @@ fn invalid_arrays() {
|
||||
})
|
||||
}
|
||||
|
||||
check_validation! {
|
||||
r#"
|
||||
fn main() -> f32 {
|
||||
let a = array<f32, 3>(0., 1., 2.);
|
||||
return a[-1];
|
||||
}
|
||||
"#:
|
||||
Err(
|
||||
naga::valid::ValidationError::Function {
|
||||
name,
|
||||
source: naga::valid::FunctionError::Expression {
|
||||
source: naga::valid::ExpressionError::NegativeIndex(_),
|
||||
..
|
||||
},
|
||||
..
|
||||
}
|
||||
)
|
||||
if name == "main"
|
||||
}
|
||||
|
||||
check(
|
||||
"alias Bad = array<f32, true>;",
|
||||
r###"error: must be a const-expression that resolves to a concrete integer scalar (u32 or i32)
|
||||
|
||||
Reference in New Issue
Block a user