aboutsummaryrefslogtreecommitdiffstats
path: root/src/constrain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/constrain.cpp')
-rw-r--r--src/constrain.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp
index a4a1ad3..78accf6 100644
--- a/src/constrain.cpp
+++ b/src/constrain.cpp
@@ -241,6 +241,8 @@ constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
THROW_IF(!pattern, exp->loc, "pattern expression expected");
const ASymbol* name = (*pattern->begin())->to_symbol();
THROW_IF(!name, (*pattern->begin())->loc, "pattern does not start with a symbol");
+ THROW_IF(!tenv.ref(name), name->loc,
+ (format("undefined constructor `%1%'") % name->sym()).str());
const AST* consT = *tenv.ref(name);
@@ -251,8 +253,16 @@ constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
THROW_IF(i == call->end(), pattern->loc, "missing pattern body");
const AST* body = *i++;
+
+ TEnv::Frame frame;
+ ATuple::const_iterator ti = consT->as_tuple()->iter_at(2);
+ for (ATuple::const_iterator pi = pattern->iter_at(1); pi != pattern->end(); ++pi)
+ frame.push_back(make_pair((*pi)->as_symbol()->sym(), *ti++));
+
+ tenv.push(frame);
resp_constrain(tenv, c, body);
- c.constrain(tenv, body, retT);
+ c.constrain(tenv, body, retT);
+ tenv.pop();
}
c.constrain(tenv, call, retT);
c.constrain(tenv, matchee, matcheeT);