[fine] fix some bugs, semantics for is

This commit is contained in:
John Doty 2024-02-03 07:59:49 -08:00
parent ba5b37f5ff
commit b5b56b49a9
4 changed files with 59 additions and 7 deletions

View file

@ -604,14 +604,13 @@ impl<'a> Semantics<'a> {
};
let result = match tree.kind {
TreeKind::LetStatement => self.environment_of_let(parent, tree),
TreeKind::ParamList => self.environment_of_paramlist(parent, tree),
TreeKind::File => self.environment_of_file(parent, tree),
TreeKind::IsExpression => self.environment_of_is_expression(parent, tree),
TreeKind::Block => self.environment_of_block(parent, tree),
TreeKind::File => self.environment_of_file(parent, tree),
TreeKind::ForStatement => self.environment_of_for(parent, tree),
TreeKind::LetStatement => self.environment_of_let(parent, tree),
TreeKind::MemberAccess => self.environment_of_member_access(tree),
TreeKind::ParamList => self.environment_of_paramlist(parent, tree),
_ => parent,
};
@ -819,6 +818,24 @@ impl<'a> Semantics<'a> {
}
}
fn environment_of_is_expression(&self, parent: EnvironmentRef, tree: &Tree) -> EnvironmentRef {
assert_eq!(tree.kind, TreeKind::IsExpression);
let Some(binding) = tree.child_tree_of_kind(self.syntax_tree, TreeKind::VariableBinding)
else {
return parent;
};
let Some(variable) = binding.nth_token(0) else {
return Environment::error();
};
let Some(type_expr) = binding.nth_tree(2) else {
return Environment::error();
};
let mut env = Environment::new(Some(parent), Location::Local);
env.insert(variable, type_expr);
return EnvironmentRef::new(env);
}
pub fn class_of(&self, t: TreeRef) -> ClassRef {
{
// I want to make sure that this borrow is dropped after this block.
@ -968,6 +985,9 @@ impl<'a> Semantics<'a> {
(Type::Error, _) => true,
(_, Type::Error) => true,
// Can... I... convert unreachable always? Is this sound?
(Type::Unreachable, _) => true,
// TODO: Unification on type variables! :D
(_, _) => false,
}
@ -1010,6 +1030,7 @@ impl<'a> Semantics<'a> {
TreeKind::GroupingExpression => self.type_of_grouping(tree),
TreeKind::Identifier => self.type_of_identifier(t, tree),
TreeKind::IfStatement => self.type_of_if_statement(tree),
TreeKind::IsExpression => Some(Type::Bool),
TreeKind::LetStatement => Some(Type::Nothing),
TreeKind::ListConstructor => self.type_of_list_constructor(t, tree),
TreeKind::ListConstructorElement => self.type_of_list_constructor_element(tree),