Skip to content
Snippets Groups Projects
Commit d3e09690 authored by Per Lindgren's avatar Per Lindgren
Browse files

borrow check, wip3

parent 4d9fd76d
No related branches found
No related tags found
No related merge requests found
fn f(a: &i32, b: &mut bool) {}
fn main() {
let mut a = 1;
let b = &mut a;
let c = &mut a;
let c: &mut i32 = b;
let mut b = false;
f(&a, &mut b)
}
fn f(a: &i32, b: &mut i32) {}
fn main() {
let mut a = 1;
f(&a, &mut a)
}
......@@ -160,12 +160,12 @@ fn expr_type(
// Convert Expr::Ref to Type::Ref
Ref(ref_e) => {
let t = expr_type(ref_e, fn_env, type_env, var_env)?;
trace!("ref_e {}, t {}", ref_e, t);
let t = match t {
Type::Mut(t) => t.clone(),
t => Box::new(t),
};
Ok(Type::Ref(t))
trace!("ref_e {}: type {}", ref_e, t);
let t = strip_mut(t);
trace!("after ref_e {}: type {}", ref_e, t);
Ok(Type::Ref(Box::new(t)))
}
// Convert Expr::Mut to Type::Mut
......@@ -373,6 +373,7 @@ pub fn check_stmts(
type_env: &TypeEnv,
var_env: &mut VarEnv,
) -> Result<Type, Error> {
trace!("check_stmts: var_env: {:?}", var_env);
var_env.push_empty_scope();
let t = stmts
......
......@@ -175,3 +175,8 @@ fn wip() {
fn borrow() {
check(&read_file::parse("examples/borrow.rs")).unwrap();
}
#[test]
fn borrow2() {
check(&read_file::parse("examples/borrow2.rs")).unwrap();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment