Fix typeinference and checking for borrows/derefs

This commit is contained in:
Sofia 2025-07-20 22:33:00 +03:00
parent 47fa5f342f
commit 550fec2827
4 changed files with 19 additions and 9 deletions

View File

@ -230,9 +230,9 @@ impl Expression {
Ok((ret_type.0, TypeKind::Borrow(Box::new(ret_type.1))))
}
Deref(var) => {
let ret_type = var.return_type()?;
match ret_type {
(_, TypeKind::Borrow(type_kind)) => Ok((ret_type.0, *type_kind)),
let (kind, ret_type) = var.return_type()?;
match ret_type.resolve_weak(refs) {
TypeKind::Borrow(type_kind) => Ok((kind, *type_kind)),
_ => Err(ReturnTypeOther::DerefNonBorrow(var.2)),
}
}

View File

@ -103,10 +103,10 @@ impl<'map> Pass for LinkerPass<'map> {
modules.insert(module.name.clone(), Rc::new(RefCell::new((module, tokens))));
}
modules.insert(
"std".to_owned(),
Rc::new(RefCell::new(compile_std(&mut self.module_map)?)),
);
// modules.insert(
// "std".to_owned(),
// Rc::new(RefCell::new(compile_std(&mut self.module_map)?)),
// );
let mut modules_to_process: Vec<Rc<RefCell<(Module, Vec<FullToken>)>>> =
modules.values().cloned().collect();

View File

@ -677,6 +677,8 @@ impl Expression {
return Err(ErrorKind::AttemptedDerefNonBorrow(var_ref.1.clone()));
};
var_ref.0 = TypeKind::Borrow(inner.clone());
Ok(*inner)
}
}

View File

@ -144,6 +144,8 @@ impl Block {
let mut ret_type_ref = outer_refs.from_type(&ty).unwrap();
// Narow return type to declared type if hard return
dbg!(&kind, ty);
if kind == ReturnKind::Hard {
if let Some(hint) = &state.scope.return_type_hint {
ret_type_ref.narrow(&mut outer_refs.from_type(&hint).unwrap());
@ -392,10 +394,16 @@ impl Expression {
var.0 = hint.as_type();
}
match &var.0.resolve_weak(type_refs.types) {
dbg!(&var.0);
dbg!(&var.0.resolve_weak(type_refs.types));
let a = match &var.0.resolve_weak(type_refs.types) {
Borrow(type_kind) => Ok(type_refs.from_type(&type_kind).unwrap()),
_ => Err(ErrorKind::AttemptedDerefNonBorrow(var.1.clone())),
}
};
dbg!(&a);
a
}
}
}