From 5aea5c77b9971bb5f63347323e76d9f92a1187ce Mon Sep 17 00:00:00 2001
From: Nicholas Robinson <nwrobins@edu.uwaterloo.ca>
Date: Fri, 6 Mar 2020 22:43:06 -0500
Subject: [PATCH] ClassCreateNode protected check

---
 ExprPrimaryNodes.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py
index ea0c0f9..44f9da8 100644
--- a/ExprPrimaryNodes.py
+++ b/ExprPrimaryNodes.py
@@ -310,6 +310,15 @@ class ClassCreateNode(ASTNode):
         else:
             raise Exception("ERROR: Class {} doesn't have a constructor with given argument types.".format(classDef.name))
 
+        # check to make sure we are allowed to call this (protected?)
+        # if self.cons is protected, check that:
+        # - current class is in the same package
+        if 'protected' in self.cons.mods:
+            curClass = self.env.getNode(self.typeName, 'type')
+
+            if curClass.packageName != classDef.packageName:
+                raise Exception("ERROR: In class {0}, using a protected constructor, but class {1} is not in class {0}'s package ({2}).".format(curClass.name, classDef.name, curClass.packageName))
+
 
 #################################################################################
 # condOrExpr
-- 
GitLab