Pass function tests
This commit is contained in:
parent
cabbf8821f
commit
764ea0550d
@ -42,8 +42,6 @@ impl AbstractTree for Assignment {
|
||||
}
|
||||
|
||||
fn validate(&self, context: &Context) -> Result<(), ValidationError> {
|
||||
self.statement.validate(context)?;
|
||||
|
||||
let statement_type = self.statement.expected_type(context)?;
|
||||
|
||||
if let Some(expected) = &self.r#type {
|
||||
@ -54,6 +52,8 @@ impl AbstractTree for Assignment {
|
||||
context.set_type(self.identifier.clone(), statement_type)?;
|
||||
}
|
||||
|
||||
self.statement.validate(context)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,8 @@ impl AbstractTree for ValueNode {
|
||||
function_context.set_type(identifier.clone(), r#type.clone())?;
|
||||
}
|
||||
|
||||
body.validate(&function_context)?;
|
||||
|
||||
let actual_return_type = body.expected_type(&function_context)?;
|
||||
|
||||
return_type.check(&actual_return_type)?;
|
||||
|
@ -6,7 +6,7 @@ use std::{
|
||||
use crate::{
|
||||
abstract_tree::{Identifier, Type},
|
||||
error::RwLockPoisonError,
|
||||
value::BuiltInFunction,
|
||||
value::{BuiltInFunction, ValueInner},
|
||||
Value,
|
||||
};
|
||||
|
||||
@ -37,10 +37,12 @@ impl Context {
|
||||
let mut new_data = BTreeMap::new();
|
||||
|
||||
for (identifier, value_data) in other.inner.read()?.iter() {
|
||||
if let ValueData::Type(_) = value_data {
|
||||
if let ValueData::Type(r#type) = value_data {
|
||||
if let Type::Function { .. } = r#type {
|
||||
new_data.insert(identifier.clone(), value_data.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self::with_data(new_data))
|
||||
}
|
||||
@ -49,8 +51,17 @@ impl Context {
|
||||
let mut new_data = BTreeMap::new();
|
||||
|
||||
for (identifier, value_data) in other.inner.read()?.iter() {
|
||||
if let ValueData::Type(r#type) = value_data {
|
||||
if let Type::Function { .. } = r#type {
|
||||
new_data.insert(identifier.clone(), value_data.clone());
|
||||
}
|
||||
}
|
||||
if let ValueData::Value(value) = value_data {
|
||||
if let ValueInner::Function { .. } = value.inner().as_ref() {
|
||||
new_data.insert(identifier.clone(), value_data.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self::with_data(new_data))
|
||||
}
|
||||
|
@ -94,8 +94,6 @@ fn function_context_captures_functions() {
|
||||
|
||||
#[test]
|
||||
fn recursion() {
|
||||
env_logger::builder().is_test(true).try_init().unwrap();
|
||||
|
||||
assert_eq!(
|
||||
interpret(
|
||||
"
|
||||
|
Loading…
Reference in New Issue
Block a user