Update unify.rs

This commit is contained in:
Shunsuke Shibayama 2023-01-09 20:34:02 +09:00
parent c7b779d74b
commit 2c1e30272a

View file

@ -27,6 +27,7 @@ impl Context {
// occur(X -> ?T, ?T) ==> Error
// occur(?T, ?T -> X) ==> Error
// occur(?T, Option(?T)) ==> Error
// occur(?T, ?T.Output) ==> Error
fn occur(&self, maybe_sub: &Type, maybe_sup: &Type, loc: Location) -> TyCheckResult<()> {
match (maybe_sub, maybe_sup) {
(Type::FreeVar(sub), Type::FreeVar(sup)) => {
@ -93,6 +94,30 @@ impl Context {
}
Ok(())
}
(Type::Proj { lhs, .. }, rhs) => self.occur(lhs, rhs, loc),
(Type::ProjCall { lhs, args, .. }, rhs) => {
if let TyParam::Type(t) = lhs.as_ref() {
self.occur(t, rhs, loc)?;
}
for arg in args.iter() {
if let TyParam::Type(t) = arg {
self.occur(t, rhs, loc)?;
}
}
Ok(())
}
(lhs, Type::Proj { lhs: rhs, .. }) => self.occur(lhs, rhs, loc),
(lhs, Type::ProjCall { lhs: rhs, args, .. }) => {
if let TyParam::Type(t) = rhs.as_ref() {
self.occur(lhs, t, loc)?;
}
for arg in args.iter() {
if let TyParam::Type(t) = arg {
self.occur(lhs, t, loc)?;
}
}
Ok(())
}
_ => Ok(()),
}
}