Implemented 'protected' on fields and methods

This commit is contained in:
ZZYZX 2017-03-05 01:03:38 +02:00 committed by Christoph Oelckers
parent 9d4179ca06
commit b87f9b540e
2 changed files with 4 additions and 4 deletions

View file

@ -6084,7 +6084,7 @@ FxExpression *FxIdentifier::ResolveMember(FCompileContext &ctx, PStruct *classct
} }
PClass* cls_ctx = dyn_cast<PClass>(classctx); PClass* cls_ctx = dyn_cast<PClass>(classctx);
PClass* cls_target = dyn_cast<PClass>(objtype); PClass* cls_target = dyn_cast<PClass>(objtype);
if ((vsym->Flags & VARF_Protected) && (!cls_ctx || !cls_target || cls_ctx->IsDescendantOf(cls_target))) if ((vsym->Flags & VARF_Protected) && (!cls_ctx || !cls_target || !cls_ctx->IsDescendantOf(cls_target)))
{ {
ScriptPosition.Message(MSG_ERROR, "Protected member %s not accessible", vsym->SymbolName.GetChars()); ScriptPosition.Message(MSG_ERROR, "Protected member %s not accessible", vsym->SymbolName.GetChars());
return nullptr; return nullptr;

View file

@ -195,8 +195,8 @@ PFunction *FindClassMemberFunction(PStruct *selfcls, PStruct *funccls, FName nam
if (symbol != nullptr) if (symbol != nullptr)
{ {
PClass* cls_ctx = dyn_cast<PClass>(selfcls); PClass* cls_ctx = dyn_cast<PClass>(funccls);
PClass* cls_target = dyn_cast<PClass>(funccls); PClass* cls_target = funcsym?dyn_cast<PClass>(funcsym->OwningClass):nullptr;
if (funcsym == nullptr) if (funcsym == nullptr)
{ {
sc.Message(MSG_ERROR, "%s is not a member function of %s", name.GetChars(), selfcls->TypeName.GetChars()); sc.Message(MSG_ERROR, "%s is not a member function of %s", name.GetChars(), selfcls->TypeName.GetChars());
@ -206,7 +206,7 @@ PFunction *FindClassMemberFunction(PStruct *selfcls, PStruct *funccls, FName nam
// private access is only allowed if the symbol table belongs to the class in which the current function is being defined. // private access is only allowed if the symbol table belongs to the class in which the current function is being defined.
sc.Message(MSG_ERROR, "%s is declared private and not accessible", symbol->SymbolName.GetChars()); sc.Message(MSG_ERROR, "%s is declared private and not accessible", symbol->SymbolName.GetChars());
} }
else if ((funcsym->Variants[0].Flags & VARF_Protected) && (!cls_ctx || !cls_target || cls_ctx->IsDescendantOf((PClass*)cls_target))) else if ((funcsym->Variants[0].Flags & VARF_Protected) && (!cls_ctx || !cls_target || !cls_ctx->IsDescendantOf((PClass*)cls_target)))
{ {
sc.Message(MSG_ERROR, "%s is declared protected and not accessible", symbol->SymbolName.GetChars()); sc.Message(MSG_ERROR, "%s is declared protected and not accessible", symbol->SymbolName.GetChars());
return nullptr; return nullptr;