From afbba9dae72043fc38360bf63690174ddcc2e1e2 Mon Sep 17 00:00:00 2001
From: Xun Yang <x299yang@uwaterloo.ca>
Date: Fri, 6 Mar 2020 19:59:45 -0500
Subject: [PATCH] fix array access

---
 ExprPrimaryNodes.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py
index eb23668..7f03549 100644
--- a/ExprPrimaryNodes.py
+++ b/ExprPrimaryNodes.py
@@ -135,11 +135,13 @@ class ArrayAccessNode(ASTNode):
     def disambigName(self):
         self.array.disambigName()
         self.index.disambigName()
-        # helperDisambigName(self.array)
-        # helperDisambigName(self.index)
+
     def checkType(self):
+        self.array.disambigName() # hacky fix, not sure why disambigName wasn't called before
         self.array.checkType()
         self.index.checkType()
+        if not self.array.myType.isArray:
+            raise Exception("ERROR: Cannot perform array access on non-array {}".format(self.array.name))
         if not self.index.myType.isNum():
             raise Exception("ERROR: Array index must be a number.")
         self.myType = TypeStruct(self.array.myType.name, self.array.myType.typePointer)
@@ -410,7 +412,7 @@ class FieldAccessNode(ASTNode):
         self.children.append(self.primary)
         self.children.append(self.ID)
 
-    def disambigName(self):    
+    def disambigName(self):
         if not self.primary: # this implies that the ID has nothing that comes before it
             # helperDisambigName(self.ID)
             self.ID.disambigName()
-- 
GitLab