]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
allow comparing explicitly against nil
authorDale Weiler <weilercdale@gmail.com>
Thu, 8 Jul 2021 03:11:17 +0000 (23:11 -0400)
committerDale Weiler <weilercdale@gmail.com>
Thu, 8 Jul 2021 03:11:17 +0000 (23:11 -0400)
parser.cpp

index 0ca7843a37c214a3e3189ff1f39474694678c28f..8aa49f77bc76f1d96219c2b77d59641775eb6008 100644 (file)
@@ -897,7 +897,11 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 out = fold::binary(ctx, generated_op, exprs[0], exprs[1]);
             break;
         case opid2('!', '='):
-            if (exprs[0]->m_vtype != exprs[1]->m_vtype) {
+            #define NotComparable \
+                exprs[0]->m_vtype != TYPE_NIL && \
+                exprs[1]->m_vtype != TYPE_NIL && \
+                exprs[0]->m_vtype != exprs[1]->m_vtype
+            if (NotComparable) {
                 compile_error(ctx, "invalid types used in expression: cannot perform comparison between types %s and %s",
                               type_name[exprs[0]->m_vtype],
                               type_name[exprs[1]->m_vtype]);
@@ -907,7 +911,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 out = fold::binary(ctx, type_ne_instr[exprs[0]->m_vtype], exprs[0], exprs[1]);
             break;
         case opid2('=', '='):
-            if (exprs[0]->m_vtype != exprs[1]->m_vtype) {
+            if (NotComparable) {
                 compile_error(ctx, "invalid types used in expression: cannot perform comparison between types %s and %s",
                               type_name[exprs[0]->m_vtype],
                               type_name[exprs[1]->m_vtype]);