Implement simple struct error
This commit is contained in:
parent
65ee161a96
commit
d46a592f87
@ -22,7 +22,9 @@ impl AbstractTree for StructureDefinition {
|
||||
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(())
|
||||
}
|
||||
|
||||
|
@ -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(())
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use dust_lang::{abstract_tree::Identifier, *};
|
||||
use dust_lang::{abstract_tree::Identifier, error::Error, *};
|
||||
|
||||
#[test]
|
||||
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()
|
||||
}])
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user