Kaynağa Gözat

Improved protection checks of inner type

Brian Fiete 2 ay önce
ebeveyn
işleme
01ba9507c0

+ 33 - 1
IDE/Tests/CompileFail001/src/Protection.bf

@@ -5,7 +5,39 @@ using System;
 namespace Tests
 {
 	class Protection
-	{        
+	{
+		class TypeA
+		{
+		    private struct TypeB { }
+
+			public TypeA mValA;
+			public TypeB mValB; //FAIL
+			public TypeC mValC; //FAIL
+
+		    private class TypeC
+		    {
+				private class TypeD { }
+
+				public class TypeE
+				{
+					private class TypeF { }
+
+					public TypeA mValA;
+					public TypeB mValB;
+					public TypeC mValC;
+					public TypeD mValD; //FAIL
+					public TypeE mValE;
+					public TypeF mValF; //FAIL
+				}
+
+				public TypeA mValA;
+				public TypeB mValB;
+				public TypeC mValC;
+				public TypeD mValD; //FAIL
+				public TypeE mValE;
+		    }
+		}
+
 		class ClassA
 		{
 			private int mAPriv;

+ 14 - 3
IDEHelper/Compiler/BfModule.cpp

@@ -3708,9 +3708,6 @@ bool BfModule::CheckAccessMemberProtection(BfProtection protection, BfTypeInstan
 
 bool BfModule::CheckDefineMemberProtection(BfProtection protection, BfType* memberType)
 {
-	// Use 'min' - exporting a 'public' from a 'private' class is really just 'private' still
-	protection = std::min(protection, mCurTypeInstance->mTypeDef->mProtection);
-
 	auto memberTypeInstance = memberType->ToTypeInstance();
 
 	if (memberTypeInstance == NULL)
@@ -3721,6 +3718,20 @@ bool BfModule::CheckDefineMemberProtection(BfProtection protection, BfType* memb
 		return true;
 	}
 
+	if (memberTypeInstance->mTypeDef->mProtection < protection)
+	{
+		// Check for any definition up to the actual declared member type
+		auto commonOuterType = FindCommonOuterType(memberTypeInstance->mTypeDef, mCurTypeInstance->mTypeDef);		
+		if (commonOuterType == memberTypeInstance->mTypeDef)
+			commonOuterType = commonOuterType->mOuterType;
+		auto checkTypeDef = mCurTypeInstance->mTypeDef;
+		while ((checkTypeDef != NULL) && (checkTypeDef != commonOuterType))
+		{
+			protection = std::min(protection, checkTypeDef->mProtection);
+			checkTypeDef = checkTypeDef->mOuterType;
+		}
+	}
+
 	if (memberTypeInstance->mTypeDef->mProtection < protection)
 		return false;