Reject empty struct types. (#1826)

This commit is contained in:
Jim Blandy
2022-04-14 09:36:53 -07:00
committed by GitHub
parent 170faab6db
commit f11d27af6f
3 changed files with 16 additions and 0 deletions

View File

@@ -676,6 +676,8 @@ pub enum TypeInner {
/// User-defined structure.
///
/// There must always be at least one member.
///
/// A `Struct` type is [`DATA`], and the types of its members must be
/// `DATA` as well.
///

View File

@@ -120,6 +120,8 @@ pub enum TypeError {
size: u32,
span: u32,
},
#[error("Structure types must have at least one member")]
EmptyStruct,
}
// Only makes sense if `flags.contains(HOST_SHARED)`
@@ -451,6 +453,10 @@ impl super::Validator {
}
}
Ti::Struct { ref members, span } => {
if members.is_empty() {
return Err(TypeError::EmptyStruct);
}
let mut ti = TypeInfo::new(
TypeFlags::DATA
| TypeFlags::SIZED

View File

@@ -930,6 +930,14 @@ fn invalid_structs() {
..
})
}
check_validation_error! {
"struct Empty {}":
Err(naga::valid::ValidationError::Type {
error: naga::valid::TypeError::EmptyStruct,
..
})
}
}
#[test]