mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-04 00:54:36 +00:00
Do an occurs check in solve
This commit is contained in:
parent
afd33c2a23
commit
b297bc2f1c
1 changed files with 16 additions and 6 deletions
22
src/solve.rs
22
src/solve.rs
|
@ -56,23 +56,27 @@ pub fn solve(
|
|||
solve(vars_by_symbol, problems, subs, &let_con.defs_constraint)
|
||||
}
|
||||
ret_con => {
|
||||
// Solve the assignments' constraints first.
|
||||
solve(vars_by_symbol, problems, subs, &let_con.defs_constraint);
|
||||
|
||||
// Add a variable for each assignment to the vars_by_symbol.
|
||||
let mut new_vars_by_symbol = vars_by_symbol.clone();
|
||||
let mut locals = vars_by_symbol.clone();
|
||||
|
||||
for (symbol, loc_type) in let_con.def_types.iter() {
|
||||
let var = type_to_var(subs, loc_type.value.clone());
|
||||
|
||||
new_vars_by_symbol.insert(symbol.clone(), var);
|
||||
locals.insert(symbol.clone(), var);
|
||||
}
|
||||
|
||||
// Solve the assignments' constraints first.
|
||||
solve(vars_by_symbol, problems, subs, &let_con.defs_constraint);
|
||||
|
||||
let new_vars_by_symbol = vars_by_symbol.clone().union(locals.clone());
|
||||
|
||||
// Now solve the body, using the new vars_by_symbol which includes
|
||||
// the assignments' name-to-variable mappings.
|
||||
solve(&new_vars_by_symbol, problems, subs, &ret_con);
|
||||
|
||||
// TODO do an occurs check for each of the assignments!
|
||||
for (_, var) in locals {
|
||||
check_occurs(subs, problems, var);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,3 +162,9 @@ fn type_to_variable(subs: &mut Subs, aliases: &ImMap<Box<str>, Variable>, typ: T
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_occurs(subs: &mut Subs, problems: &mut Problems, var: Variable) {
|
||||
if subs.occurs(var) {
|
||||
panic!("TODO record Infinite Type error in problems");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue