[naga wgsl] all swizzle components must be either color or dimension (#6187)

This commit is contained in:
Samson 2024-08-31 11:08:34 +02:00 committed by GitHub
parent 04618b36a8
commit 585f4a1036
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -907,7 +907,13 @@ impl Components {
*comp = Self::letter_component(ch).ok_or(Error::BadAccessor(name_span))?;
}
Ok(Components::Swizzle { size, pattern })
if name.chars().all(|c| matches!(c, 'x' | 'y' | 'z' | 'w'))
|| name.chars().all(|c| matches!(c, 'r' | 'g' | 'b' | 'a'))
{
Ok(Components::Swizzle { size, pattern })
} else {
Err(Error::BadAccessor(name_span))
}
}
}

View File

@ -2371,3 +2371,21 @@ fn local_const_from_global_var() {
"###,
);
}
#[test]
fn only_one_swizzle_type() {
check(
"
const ok1 = vec2(0.0, 0.0).xy;
const ok2 = vec2(0.0, 0.0).rg;
const err = vec2(0.0, 0.0).xg;
",
r###"error: invalid field accessor `xg`
wgsl:4:36
4 const err = vec2(0.0, 0.0).xg;
^^ invalid accessor
"###,
);
}