Browse Source

pointers can be compared with null as they should

Kajetan Johannes Hammerle 3 years ago
parent
commit
5669ee38e7
3 changed files with 6 additions and 1 deletions
  1. 1 1
      Compiler.c
  2. 3 0
      tests/types/null
  3. 2 0
      tests/types/null.out

+ 1 - 1
Compiler.c

@@ -607,7 +607,7 @@ static void cAddTypeOperation(DataType* a, Parser bf, const TypedOp* op) {
     DataType b = cUnpack(bf());
     a->constant = 0;
     b.constant = 0;
-    if(!dtCompare(*a, b)) {
+    if(!dtNullCompare(*a, b)) {
         cInvalidOperation(*a, b, op->name);
     } else if(dtIsInt32(*a) && op->intOp != OP_NOTHING) {
         cAddOperation(op->intOp);

+ 3 - 0
tests/types/null

@@ -8,4 +8,7 @@ void main() {
     test(b == *c);
     test(length(b));
     test(length(c));
+    test(b == nullptr);
+    const int** w = b;
+    test(w == nullptr);
 }

+ 2 - 0
tests/types/null.out

@@ -1,3 +1,5 @@
 true
 0
 1
+true
+true