mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[wgsl-in] eagerly evaluate const-expressions
[wgsl-in] support const-expressions in attributes allow `Splat` as an evaluated const-expression type
This commit is contained in:
@@ -107,24 +107,24 @@ 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 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() {
|
||||
@@ -923,11 +923,11 @@ fn invalid_arrays() {
|
||||
|
||||
check(
|
||||
"alias Bad = array<f32, true>;",
|
||||
r###"error: array element count must resolve to an integer scalar (u32 or i32)
|
||||
r###"error: must be a const-expression that resolves to a concrete integer scalar (u32 or i32)
|
||||
┌─ wgsl:1:24
|
||||
│
|
||||
1 │ alias Bad = array<f32, true>;
|
||||
│ ^^^^ must resolve to u32/i32
|
||||
│ ^^^^ must resolve to u32 or i32
|
||||
|
||||
"###,
|
||||
);
|
||||
@@ -937,33 +937,33 @@ fn invalid_arrays() {
|
||||
const length: f32 = 2.718;
|
||||
alias Bad = array<f32, length>;
|
||||
"#,
|
||||
r###"error: array element count must resolve to an integer scalar (u32 or i32)
|
||||
r###"error: must be a const-expression that resolves to a concrete integer scalar (u32 or i32)
|
||||
┌─ wgsl:3:36
|
||||
│
|
||||
3 │ alias Bad = array<f32, length>;
|
||||
│ ^^^^^^ must resolve to u32/i32
|
||||
│ ^^^^^^ must resolve to u32 or i32
|
||||
|
||||
"###,
|
||||
);
|
||||
|
||||
check(
|
||||
"alias Bad = array<f32, 0>;",
|
||||
r###"error: array element count must be greater than zero
|
||||
r###"error: array element count must be positive (> 0)
|
||||
┌─ wgsl:1:24
|
||||
│
|
||||
1 │ alias Bad = array<f32, 0>;
|
||||
│ ^ must be greater than zero
|
||||
│ ^ must be positive
|
||||
|
||||
"###,
|
||||
);
|
||||
|
||||
check(
|
||||
"alias Bad = array<f32, -1>;",
|
||||
r###"error: array element count must be greater than zero
|
||||
r###"error: array element count must be positive (> 0)
|
||||
┌─ wgsl:1:24
|
||||
│
|
||||
1 │ alias Bad = array<f32, -1>;
|
||||
│ ^^ must be greater than zero
|
||||
│ ^^ must be positive
|
||||
|
||||
"###,
|
||||
);
|
||||
@@ -1759,47 +1759,47 @@ fn assign_to_let() {
|
||||
"###,
|
||||
);
|
||||
|
||||
check(
|
||||
"
|
||||
fn f() {
|
||||
let a = array(1, 2);
|
||||
a[0] = 1;
|
||||
}
|
||||
",
|
||||
r###"error: invalid left-hand side of assignment
|
||||
┌─ wgsl:3:17
|
||||
│
|
||||
3 │ let a = array(1, 2);
|
||||
│ ^ this is an immutable binding
|
||||
4 │ a[0] = 1;
|
||||
│ ^^^^ cannot assign to this expression
|
||||
│
|
||||
= note: consider declaring 'a' with `var` instead of `let`
|
||||
// check(
|
||||
// "
|
||||
// fn f() {
|
||||
// let a = array(1, 2);
|
||||
// a[0] = 1;
|
||||
// }
|
||||
// ",
|
||||
// r###"error: invalid left-hand side of assignment
|
||||
// ┌─ wgsl:3:17
|
||||
// │
|
||||
// 3 │ let a = array(1, 2);
|
||||
// │ ^ this is an immutable binding
|
||||
// 4 │ a[0] = 1;
|
||||
// │ ^^^^ cannot assign to this expression
|
||||
// │
|
||||
// = note: consider declaring 'a' with `var` instead of `let`
|
||||
|
||||
"###,
|
||||
);
|
||||
// "###,
|
||||
// );
|
||||
|
||||
check(
|
||||
"
|
||||
struct S { a: i32 }
|
||||
// check(
|
||||
// "
|
||||
// struct S { a: i32 }
|
||||
|
||||
fn f() {
|
||||
let a = S(10);
|
||||
a.a = 20;
|
||||
}
|
||||
",
|
||||
r###"error: invalid left-hand side of assignment
|
||||
┌─ wgsl:5:17
|
||||
│
|
||||
5 │ let a = S(10);
|
||||
│ ^ this is an immutable binding
|
||||
6 │ a.a = 20;
|
||||
│ ^^^ cannot assign to this expression
|
||||
│
|
||||
= note: consider declaring 'a' with `var` instead of `let`
|
||||
// fn f() {
|
||||
// let a = S(10);
|
||||
// a.a = 20;
|
||||
// }
|
||||
// ",
|
||||
// r###"error: invalid left-hand side of assignment
|
||||
// ┌─ wgsl:5:17
|
||||
// │
|
||||
// 5 │ let a = S(10);
|
||||
// │ ^ this is an immutable binding
|
||||
// 6 │ a.a = 20;
|
||||
// │ ^^^ cannot assign to this expression
|
||||
// │
|
||||
// = note: consider declaring 'a' with `var` instead of `let`
|
||||
|
||||
"###,
|
||||
);
|
||||
// "###,
|
||||
// );
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user