Implement simple struct error

This commit is contained in:
Jeff 2024-03-19 19:46:41 -04:00
parent 65ee161a96
commit d46a592f87
3 changed files with 29 additions and 2 deletions

View File

@ -22,7 +22,9 @@ impl AbstractTree for StructureDefinition {
Ok(Type::None) Ok(Type::None)
} }
fn validate(&self, _context: &Context) -> Result<(), ValidationError> { fn validate(&self, context: &Context) -> Result<(), ValidationError> {
context.set_type(self.name.clone(), Type::Named(self.name.clone()))?;
Ok(()) Ok(())
} }

View File

@ -114,6 +114,14 @@ impl AbstractTree for ValueNode {
})?; })?;
} }
if let ValueNode::Structure { name, fields } = self {
let r#type = if let Some(r#type) = context.get_type(name)? {
r#type
} else {
return Err(ValidationError::TypeNotFound(name.clone()));
};
}
Ok(()) Ok(())
} }

View File

@ -1,4 +1,4 @@
use dust_lang::{abstract_tree::Identifier, *}; use dust_lang::{abstract_tree::Identifier, error::Error, *};
#[test] #[test]
fn simple_structure() { fn simple_structure() {
@ -57,3 +57,20 @@ fn nested_structure() {
))) )))
) )
} }
#[test]
fn undefined_struct() {
assert_eq!(
interpret(
"
Foo {
bar = 42
}
"
),
Err(vec![Error::Validation {
error: error::ValidationError::TypeNotFound(Identifier::new("Foo")),
position: (17, 82).into()
}])
)
}