From d2c34198db88c8ffdf9a9352825a71c85a00c26e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 7 Mar 2009 01:31:31 +0000 Subject: Fix if type checking for arc style if. git-svn-id: http://svn.drobilla.net/resp/tuplr@68 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- typing.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'typing.cpp') 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(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 -- cgit v1.2.1