From e78369a8974760bcd8aa3f7d5387b378f793f8c9 Mon Sep 17 00:00:00 2001
From: Nicholas Robinson <nwrobins@edu.uwaterloo.ca>
Date: Fri, 6 Mar 2020 18:09:44 -0500
Subject: [PATCH] NameNode primitive type & ClassNode better errors

- ClassInterNode better errors
- NameNode:checkStatic fix what happens when we encounter a primitive
type
---
 NameNode.py  | 8 ++++++--
 TypeNodes.py | 8 ++++----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/NameNode.py b/NameNode.py
index b89110f..141b789 100644
--- a/NameNode.py
+++ b/NameNode.py
@@ -118,7 +118,12 @@ class NameNode(ASTNode):
 
                 typeFieldNode = typeNode.env.getNode(staticFieldName, "fieldDcl")
                 if "static" in typeFieldNode.mods:
-                    self.prefixLink = typeFieldNode.variableDcl.dclType.myType.typePointer
+                    self.prefixLink = typeFieldNode.variableDcl
+                    
+                    # if it is primitive, then we leave it as a VarDclNode
+                    if not self.prefixLink.dclType.myType.isPrimitive:
+                        self.prefixLink = self.prefixLink.dclType.myType.typePointer
+                    
                     self.prefix = currPrefix + "." + staticFieldName
                     self.IDs = self.IDs[index+2:]
                     return True
@@ -163,7 +168,6 @@ class NameNode(ASTNode):
         # type checking: go through each prefix and determine what type it is, get that type, and check if that type contains the next access
         # eg: a.b.c.d - disambigName would have already determined what the heck the shortest prefix is for this, so take that (let's say it's a.b) then check type c, see if it contains d, then get d return type and add it to self.myType
 
-
         if not self.prefixLink or self.prefixLink == 'contain':
             self.prefixLink = self
 
diff --git a/TypeNodes.py b/TypeNodes.py
index 1f793e6..1f10b13 100644
--- a/TypeNodes.py
+++ b/TypeNodes.py
@@ -319,18 +319,18 @@ def safeReplace(cur, new, className):
 
     # 11. A nonstatic method must not replace a static method
     if 'static' in cur.mods and 'static' not in new.mods:
-        raise Exception("ERROR: Non-static {0} '{1}' in class '{2}' replaces static {0}".format(methodOrField, new.name, className))
+        raise Exception("ERROR: In class {0}, non-static {1} '{2}' in class '{3}' replaces static {1} in class/interface {3}".format(className, methodOrField, new.name, new.typeName, cur.typeName))
 
     # 9. A class/interface must not contain two methods with the same signature but different return types
     # 12. A method must not replace a method with a different return type
     if isinstance(cur, MethodNode) and cur.methodType != new.methodType:
-        raise Exception("ERROR: Method '{}' in class '{}' replaces method with a different return type".format(className, cur.name))
+        raise Exception("ERROR: In class {}, method '{}' in class '{}' replaces method with a different return type in class/interface {}".format(className, new.name, new.typeName, cur.typeName))
 
     # 13. A protected method must not replace a public method
     if 'public' in cur.mods and 'protected' in new.mods:
-        raise Exception("ERROR: Protected {0} '{1}' in class '{2}' replaces public {0}".format(methodOrField, new.name, className))
+        raise Exception("ERROR: In class {0}, protected {1} '{2}' from class '{3}' replaces public {1} from class/interface {4}".format(className, methodOrField, new.name, new.typeName, cur.typeName))
 
     # 14. A method must not replace a final method
     # quick fix for final method getClass from java.lang.Object
     if 'final' in cur.mods and cur.name != 'getClass':
-        raise Exception("ERROR: {} '{}' in class '{}' replaces final {}".format(methodOrField.capitalize(), cur.name, className, methodOrField))
+        raise Exception("ERROR: In class {0}, {1} '{2}' in class '{3}' replaces final {1} in class/interface {4}".format(className, methodOrField, new.name, new.typeName, cur.typeName))
-- 
GitLab