aboutsummaryrefslogtreecommitdiffstats
path: root/src/unify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unify.cpp')
-rw-r--r--src/unify.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/unify.cpp b/src/unify.cpp
index 48818e9..52a3265 100644
--- a/src/unify.cpp
+++ b/src/unify.cpp
@@ -119,6 +119,13 @@ Constraints::replace(const AType* s, const AType* t)
return *this;
}
+static inline bool
+is_dots(const AST* ast)
+{
+ const AType* type = ast->as_type();
+ return (type->kind == AType::NAME && type->head()->str() == "...");
+}
+
/// Unify a type constraint set (TAPL 22.4)
Subst
unify(const Constraints& constraints)
@@ -143,13 +150,14 @@ unify(const Constraints& constraints)
for (; si != s->end() && ti != t->end(); ++si, ++ti) {
const AType* st = (*si)->as_type();
const AType* tt = (*ti)->as_type();
- if (st->kind == AType::DOTS || tt->kind == AType::DOTS)
+ if (is_dots(st) || is_dots(tt))
return unify(cp);
else
cp.push_back(Constraint(st, tt));
}
- if ( (si == s->end() && (ti == t->end() || (*ti)->as_type()->kind == AType::DOTS))
- || (ti == t->end() && (*si)->as_type()->kind == AType::DOTS))
+ if ((si == s->end() && ti == t->end())
+ || (si != s->end() && is_dots(*si))
+ || (ti != t->end() && is_dots(*ti)))
return unify(cp);
}
throw Error(s->loc,