diff options
Diffstat (limited to 'src/unify.cpp')
-rw-r--r-- | src/unify.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/unify.cpp b/src/unify.cpp index f8ebe1d..9bb2f3c 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -66,12 +66,14 @@ substitute(const AST* in, const AST* from, const AST* to) return to; const ATuple* tup = in->to_tuple(); - if (!tup) + if (!tup || !tup->fst()) return from; List ret; for (const auto& i : *tup->as_tuple()) { - if (*i == *from) { + if (!i) { + continue; + } if (*i == *from) { ret.push_back(to); // FIXME: should be a copy w/ (*i)->loc } else if (i != to) { if (AType::is_expr(i)) @@ -123,7 +125,7 @@ Constraints::replace(const AST* s, const AST* t) } if (*c.second == *s) { c.second = t; // FIXME: should be copy w/ c.second->loc; - } else if (AType::is_expr(c.second)) { + } else if (AType::is_expr(c.second) && c.second->to_tuple()->fst()) { c.second = substitute(c.second, s, t); } } @@ -156,8 +158,10 @@ unify(const Constraints& constraints) for (; si != st->end() && ti != tt->end(); ++si, ++ti) { if (is_dots(*si) || is_dots(*ti)) return unify(cp); - else + else if (*si && *ti) cp.push_back(Constraint(*si, *ti)); + else + throw Error(Cursor(), "match with missing list element"); } if ((si == st->end() && ti == tt->end()) || (si != st->end() && is_dots(*si)) |