diff options
Diffstat (limited to 'src/unify.cpp')
-rw-r--r-- | src/unify.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/unify.cpp b/src/unify.cpp index 5284bea..92957c0 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -32,7 +32,6 @@ TEnv::buildSubst(AType* genericT, const AType& argsT) // Build substitution to apply to generic type const ATuple* genericProtT = (*(genericT->begin() + 1))->as<const ATuple*>(); - assert(argsT.size() == genericProtT->size()); ATuple::const_iterator g = genericProtT->begin(); AType::const_iterator a = argsT.begin(); for (; a != argsT.end(); ++a, ++g) { @@ -40,7 +39,6 @@ TEnv::buildSubst(AType* genericT, const AType& argsT) AType* callArgT = (*a)->to<AType*>(); if (callArgT->kind == AType::EXPR) { assert(genericArgT->kind == AType::EXPR); - assert(callArgT->size() == genericArgT->size()); ATuple::const_iterator gi = genericArgT->begin(); ATuple::const_iterator ci = callArgT->begin(); for (; gi != genericArgT->end(); ++gi, ++ci) { @@ -125,18 +123,18 @@ unify(const Constraints& constraints) } else if (t->kind == AType::VAR && !s->contains(t)) { cp.replace(t, s); return Subst::compose(unify(cp), Subst(t, s)); - } else if (s->kind == AType::EXPR && s->kind == t->kind && s->size() == t->size()) { + } else if (s->kind == AType::EXPR && t->kind == AType::EXPR) { AType::iterator si = s->begin() + 1; AType::iterator ti = t->begin() + 1; - for (; si != s->end(); ++si, ++ti) { + for (; si != s->end() && ti != t->end(); ++si, ++ti) { AType* st = (*si)->to<AType*>(); AType* tt = (*ti)->to<AType*>(); assert(st && tt); cp.push_back(Constraint(st, tt, st->loc)); } - return unify(cp); - } else { - throw Error(s->loc ? s->loc : t->loc, - (format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str()); + if (si == s->end() && ti == t->end()) + return unify(cp); } + throw Error(s->loc ? s->loc : t->loc, + (format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str()); } |