mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 10:23:20 +00:00
Update unify.rs
This commit is contained in:
parent
c7b779d74b
commit
2c1e30272a
1 changed files with 25 additions and 0 deletions
|
@ -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(()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue