1.1 --- a/jitcraft/SemanticAnalysis.cpp Tue Jul 17 03:59:52 2012 -0700
1.2 +++ b/jitcraft/SemanticAnalysis.cpp Tue Jul 17 21:40:44 2012 -0700
1.3 @@ -207,7 +207,13 @@
1.4 }
1.5 }
1.6
1.7 - if (token >= TOK_EQUALS && token <= TOK_OR) {
1.8 + if (token == TOK_OR || token == TOK_AND) {
1.9 + if (!canTest(node, left) || !canTest(node, right))
1.10 + return NULL;
1.11 + return zone_->types()->getPrimitive(PrimitiveType_Int32);
1.12 + }
1.13 +
1.14 + if (token >= TOK_EQUALS && token <= TOK_GE) {
1.15 if ((left->isFloat() || (left->isInt32() && !left->tag())) &&
1.16 (right->isFloat() || (right->isInt32() && !right->tag())))
1.17 {
1.18 @@ -230,7 +236,7 @@
1.19 bool
1.20 SemanticAnalysis::canTest(AstNode *node, Handle<Type> type)
1.21 {
1.22 - if (type->isArray()) {
1.23 + if (type->isArray() || (type->isInt32() && type->tag())) {
1.24 cc_.reportError(node->pos(), Message_ArrayIsNotBoolean);
1.25 return false;
1.26 }
1.27 @@ -340,13 +346,21 @@
1.28
1.29 switch (node->token())
1.30 {
1.31 + case TOK_NOT:
1.32 + if (!canTest(node->expression(), type))
1.33 + return;
1.34 + type = zone_->types()->getPrimitive(PrimitiveType_Int32);
1.35 + if (!type)
1.36 + return;
1.37 + node->setType(type);
1.38 + break;
1.39 +
1.40 default:
1.41 assert(node->token() == TOK_TILDE);
1.42 if (!type->isInt32() || type->tag()) {
1.43 unaryTypeError(node, node->token(), type);
1.44 return;
1.45 }
1.46 -
1.47 node->setType(type);
1.48 break;
1.49 }