diff -r 93e0a19c805a -r 0206df35882c jitcraft/SemanticAnalysis.cpp --- a/jitcraft/SemanticAnalysis.cpp Tue Jul 17 03:59:52 2012 -0700 +++ b/jitcraft/SemanticAnalysis.cpp Tue Jul 17 21:40:44 2012 -0700 @@ -207,7 +207,13 @@ } } - if (token >= TOK_EQUALS && token <= TOK_OR) { + if (token == TOK_OR || token == TOK_AND) { + if (!canTest(node, left) || !canTest(node, right)) + return NULL; + return zone_->types()->getPrimitive(PrimitiveType_Int32); + } + + if (token >= TOK_EQUALS && token <= TOK_GE) { if ((left->isFloat() || (left->isInt32() && !left->tag())) && (right->isFloat() || (right->isInt32() && !right->tag()))) { @@ -230,7 +236,7 @@ bool SemanticAnalysis::canTest(AstNode *node, Handle type) { - if (type->isArray()) { + if (type->isArray() || (type->isInt32() && type->tag())) { cc_.reportError(node->pos(), Message_ArrayIsNotBoolean); return false; } @@ -340,13 +346,21 @@ switch (node->token()) { + case TOK_NOT: + if (!canTest(node->expression(), type)) + return; + type = zone_->types()->getPrimitive(PrimitiveType_Int32); + if (!type) + return; + node->setType(type); + break; + default: assert(node->token() == TOK_TILDE); if (!type->isInt32() || type->tag()) { unaryTypeError(node, node->token(), type); return; } - node->setType(type); break; }