Functions can take pointers to unsized structs, but no other unsized types.

This commit is contained in:
Jim Blandy authored and Dzmitry Malyshau committed 2021-06-18 20:44:07 -04:00
1 parent fd3b2a93d4
commit 1d0b3f3a75
3 files changed
+68 -3

No files matched your search

+8
View File
@@ -37,6 +37,8 @@ pub enum CallError {
#[derive(Clone, Debug, thiserror::Error)]
#[cfg_attr(test, derive(PartialEq))]
pub enum LocalVariableError {
#[error("Local variable has a type {0:?} that can't be stored in a local variable.")]
InvalidType(Handle<crate::Type>),
#[error("Initializer doesn't match the variable type")]
InitializerType,
}
@@ -517,6 +519,12 @@ impl super::Validator {
constants: &Arena<crate::Constant>,
) -> Result<(), LocalVariableError> {
log::debug!("var {:?}", var);
if !self.types[var.ty.index()]
.flags
.contains(TypeFlags::DATA | TypeFlags::SIZED)
{
return Err(LocalVariableError::InvalidType(var.ty));
}
if let Some(const_handle) = var.init {
match constants[const_handle].inner {
crate::ConstantInner::Scalar { width, ref value } => {