Begin passing tests
This commit is contained in:
parent
4b89ea0e96
commit
240c045a0c
@ -151,24 +151,26 @@ impl AbstractNode for ValueNode {
|
|||||||
|
|
||||||
body.node.validate(&mut function_context, _manage_memory)?;
|
body.node.validate(&mut function_context, _manage_memory)?;
|
||||||
|
|
||||||
let (expected_return_type, expected_position) = if let Some(constructor) = return_type {
|
let ((expected_return, expected_position), actual_return) =
|
||||||
(constructor.construct(context)?, constructor.position())
|
match (return_type, body.node.expected_type(context)?) {
|
||||||
} else {
|
(Some(constructor), Some(r#type)) => (
|
||||||
return Err(ValidationError::ExpectedExpression(body.position));
|
(constructor.construct(context)?, constructor.position()),
|
||||||
};
|
r#type,
|
||||||
let actual_return_type = if let Some(r#type) = body.node.expected_type(context)? {
|
),
|
||||||
r#type
|
(None, Some(_)) => return Err(ValidationError::ExpectedValue(body.position)),
|
||||||
} else {
|
(Some(constructor), None) => {
|
||||||
return Err(ValidationError::ExpectedExpression(body.position));
|
return Err(ValidationError::ExpectedExpression(constructor.position()))
|
||||||
};
|
}
|
||||||
|
(None, None) => return Ok(()),
|
||||||
|
};
|
||||||
|
|
||||||
expected_return_type
|
expected_return.check(&actual_return).map_err(|conflict| {
|
||||||
.check(&actual_return_type)
|
ValidationError::TypeCheck {
|
||||||
.map_err(|conflict| ValidationError::TypeCheck {
|
|
||||||
conflict,
|
conflict,
|
||||||
actual_position: body.position,
|
actual_position: body.position,
|
||||||
expected_position: Some(expected_position),
|
expected_position: Some(expected_position),
|
||||||
})?;
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -427,6 +427,29 @@ fn list_of_type() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_type() {
|
fn function_type() {
|
||||||
|
assert_eq!(
|
||||||
|
parse(&lex("type Foo = fn |T| (int)").unwrap()).unwrap()[0],
|
||||||
|
Statement::TypeAlias(
|
||||||
|
TypeAlias::new(
|
||||||
|
Identifier::new("Foo").with_position((5, 8)),
|
||||||
|
TypeConstructor::Function(
|
||||||
|
FunctionTypeConstructor {
|
||||||
|
type_parameters: Some(vec![Identifier::new("T").with_position((15, 16))]),
|
||||||
|
value_parameters: vec![TypeConstructor::Raw(
|
||||||
|
RawTypeConstructor::Integer.with_position((19, 22))
|
||||||
|
)],
|
||||||
|
return_type: None
|
||||||
|
}
|
||||||
|
.with_position((11, 23))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.with_position((0, 23))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn function_type_with_return() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse(&lex("type Foo = fn |T| (int) -> T").unwrap()).unwrap()[0],
|
parse(&lex("type Foo = fn |T| (int) -> T").unwrap()).unwrap()[0],
|
||||||
Statement::TypeAlias(
|
Statement::TypeAlias(
|
||||||
@ -666,7 +689,7 @@ fn map() {
|
|||||||
),
|
),
|
||||||
])
|
])
|
||||||
.with_position((0, 15))
|
.with_position((0, 15))
|
||||||
),)
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user