aboutsummaryrefslogtreecommitdiffstats
path: root/typing.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-03-07 01:31:31 +0000
committerDavid Robillard <d@drobilla.net>2009-03-07 01:31:31 +0000
commitd2c34198db88c8ffdf9a9352825a71c85a00c26e (patch)
tree5a89ae5a4f2e5a94f858163fd476051c2ad04e41 /typing.cpp
parent1865e80acca50f58cae41e8ed4e86a9c67e3a1ef (diff)
downloadresp-d2c34198db88c8ffdf9a9352825a71c85a00c26e.tar.gz
resp-d2c34198db88c8ffdf9a9352825a71c85a00c26e.tar.bz2
resp-d2c34198db88c8ffdf9a9352825a71c85a00c26e.zip
Fix if type checking for arc style if.
git-svn-id: http://svn.drobilla.net/resp/tuplr@68 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'typing.cpp')
-rw-r--r--typing.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/typing.cpp b/typing.cpp
index c9febda..5e419fd 100644
--- a/typing.cpp
+++ b/typing.cpp
@@ -59,8 +59,7 @@ ASTCall::constrain(TEnv& tenv) const
void
ASTDefinition::constrain(TEnv& tenv) const
{
- if (size() != 3)
- throw Error("`def' requires exactly 2 arguments", exp.loc);
+ if (size() != 3) throw Error("`def' requires exactly 2 arguments", exp.loc);
if (!dynamic_cast<const ASTSymbol*>(at(1)))
throw Error("`def' name is not a symbol", exp.loc);
FOREACH(const_iterator, p, *this)
@@ -73,12 +72,19 @@ ASTDefinition::constrain(TEnv& tenv) const
void
ASTIf::constrain(TEnv& tenv) const
{
+ if (size() < 3) throw Error("`if' requires exactly 3 arguments", exp.loc);
+ if (size() % 2 != 0) throw Error("`if' missing final else clause", exp.loc);
FOREACH(const_iterator, p, *this)
(*p)->constrain(tenv);
- AType* tvar = tenv.type(this);
- tenv.constrain(at(1), tenv.named("Bool"));
- tenv.constrain(at(2), tvar);
- tenv.constrain(at(3), tvar);
+ AType* retT = tenv.type(this);
+ for (size_t i = 1; i < size(); i += 2) {
+ if (i == size() - 1) {
+ tenv.constrain(at(i), retT);
+ } else {
+ tenv.constrain(at(i), tenv.named("Bool"));
+ tenv.constrain(at(i+1), retT);
+ }
+ }
}
void