aboutsummaryrefslogtreecommitdiffstats
path: root/typing.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'typing.cpp')
-rw-r--r--typing.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/typing.cpp b/typing.cpp
index 389edf0..c9febda 100644
--- a/typing.cpp
+++ b/typing.cpp
@@ -134,6 +134,7 @@ ASTPrimitive::constrain(TEnv& tenv) const
void
ASTConsCall::constrain(TEnv& tenv) const
{
+ if (size() != 3) throw Error("`cons' requires exactly 2 arguments", loc);
AType* t = new AType(ASTTuple(tenv.penv.sym("Pair"), 0), loc);
for (size_t i = 1; i < size(); ++i) {
at(i)->constrain(tenv);
@@ -145,9 +146,10 @@ ASTConsCall::constrain(TEnv& tenv) const
void
ASTCarCall::constrain(TEnv& tenv) const
{
+ if (size() != 2) throw Error("`car' requires exactly 1 argument", loc);
at(1)->constrain(tenv);
AType* ct = tenv.var(loc);
- AType* tt = new AType(ASTTuple(tenv.penv.sym("Pair"), ct, tenv.var(at(2)->loc), 0), loc);
+ AType* tt = new AType(ASTTuple(tenv.penv.sym("Pair"), ct, tenv.var(), 0), loc);
tenv.constrain(at(1), tt);
tenv.constrain(this, ct);
}
@@ -155,9 +157,10 @@ ASTCarCall::constrain(TEnv& tenv) const
void
ASTCdrCall::constrain(TEnv& tenv) const
{
+ if (size() != 2) throw Error("`cdr' requires exactly 1 argument", loc);
at(1)->constrain(tenv);
AType* ct = tenv.var(loc);
- AType* tt = new AType(ASTTuple(tenv.penv.sym("Pair"), tenv.var(at(1)->loc), ct, 0), loc);
+ AType* tt = new AType(ASTTuple(tenv.penv.sym("Pair"), tenv.var(), ct, 0), loc);
tenv.constrain(at(1), tt);
tenv.constrain(this, ct);
}