From 01ba9507c0a39b2acdbad4d3bdf82977423e3965 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 15 May 2025 17:04:25 +0200 Subject: [PATCH] Improved protection checks of inner type --- IDE/Tests/CompileFail001/src/Protection.bf | 34 +++++++++++++++++++++- IDEHelper/Compiler/BfModule.cpp | 17 +++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/IDE/Tests/CompileFail001/src/Protection.bf b/IDE/Tests/CompileFail001/src/Protection.bf index d4cda719..c93502b2 100644 --- a/IDE/Tests/CompileFail001/src/Protection.bf +++ b/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; diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 3c6916fe..3f73dbbe 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/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;