From 528fced29e43b6b9841b8ea8134c6e9d415e635b Mon Sep 17 00:00:00 2001
From: Xun Yang <x299yang@uwaterloo.ca>
Date: Mon, 13 Apr 2020 16:00:52 -0400
Subject: [PATCH] cast null

---
 ExprPrimaryNodes.py | 4 ++--
 TheTypeNode.py      | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py
index 3fa30e0..635d134 100644
--- a/ExprPrimaryNodes.py
+++ b/ExprPrimaryNodes.py
@@ -426,7 +426,7 @@ class CastNode(ASTNode):
 
         # only test if not primitive
         if self.right.myType.isArray ==  self.left.myType.isArray:
-            if (not self.left.myType.isPrimitive):
+            if (not self.right.myType.isPrimitive):
                 # cast would've exception if array is casting to non-array and not Object
                 offset = self.left.myType.typePointer.subTypeOffset
                 self.code += p("mov", "ebx", "[eax]", "start subtype test") # access class tag of left object
@@ -703,7 +703,7 @@ class ExprNode(ASTNode):
 
             # only test if non-primitive, both arrays or both non arrays
             if self.right.myType.isArray == self.left.myType.isArray:
-                if not self.right.myType.isPrimitive:
+                if not self.left.myType.isPrimitive:
                     offset = self.right.myType.typePointer.subTypeOffset
                     self.code += p("mov", "eax", "[eax]") # access class tag of left object
                     self.code += p("mov", "eax", "[eax + 4]") # access subtype testing column
diff --git a/TheTypeNode.py b/TheTypeNode.py
index 40d6498..5100a73 100644
--- a/TheTypeNode.py
+++ b/TheTypeNode.py
@@ -41,7 +41,7 @@ class TypeStruct():
         self.isPrimitive = False
         self.typePointer = typePointer
         self.name = name
-        if name in ['boolean', 'byte', 'char', 'int', 'short', 'void']:
+        if name in ['boolean', 'byte', 'char', 'int', 'short', 'void', 'null']:
             self.isPrimitive = True
 
     def link(self, env):
-- 
GitLab