fix(compiler): infinite recursion bug of derefine

This commit is contained in:
Shunsuke Shibayama 2023-02-18 00:43:52 +09:00
parent 3aeb63f51b
commit 7389f68e3e
4 changed files with 21 additions and 3 deletions

View file

@ -23,7 +23,7 @@
'''
'''erg
assert [1, 1, 2].dedup() == [1, 2]
assert [0.0, 0.1, 10.0, 20.0, 20.1].dedup((lhs, rhs) -> abs(lhs - rhs) < 1.0) == [0.0, 10.0, 20.1]
assert [0.0, 0.1, 10.0, 20.0, 20.1].dedup((lhs, rhs) -> abs(lhs - rhs) < 1.0) == [0.1, 10.0, 20.1]
'''
dedup: |T: Type|(self: Array(T, _), same_bucket := (T, T) -> Bool) -> Array(T, _)
'''

View file

@ -1879,9 +1879,13 @@ impl Type {
let name = fv.unbound_name().unwrap();
let level = fv.level().unwrap();
if let Some((sub, sup)) = fv.get_subsup() {
// if fv == ?T(:> {1, 2}, <: Sub(?T)), derefine() will cause infinite loop
// so we need to force linking
fv.forced_undoable_link(&sub);
let constraint = Constraint::new_sandwiched(sub.derefine(), sup.derefine());
// not `.update_constraint`
Self::FreeVar(Free::new_named_unbound(name, level, constraint))
let free = Self::FreeVar(Free::new_named_unbound(name, level, constraint));
fv.undo();
free
} else {
let t = fv.get_type().unwrap().derefine();
let constraint = Constraint::new_type_of(t);