Fixed: check protected fields against analog of OwningClass in functions, as opposed to the type that the field was accessed from.

This commit is contained in:
ZZYZX 2017-03-05 01:47:01 +02:00 committed by Christoph Oelckers
parent 3eafc13b08
commit 1832531726

View file

@ -6084,12 +6084,36 @@ 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))) // [ZZ] neither PSymbol, PField or PSymbolTable have the necessary information. so we need to do the more complex check here.
if (vsym->Flags & VARF_Protected)
{
// early break.
if (!cls_ctx || !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;
} }
// find the class that declared this field.
PClass* p = cls_target;
while (p)
{
if (&p->Symbols == symtbl)
{
cls_target = p;
break;
}
p = p->ParentClass;
}
if (!cls_ctx->IsDescendantOf(cls_target))
{
ScriptPosition.Message(MSG_ERROR, "Protected member %s not accessible", vsym->SymbolName.GetChars());
return nullptr;
}
}
auto x = isclass ? new FxClassMember(object, vsym, ScriptPosition) : new FxStructMember(object, vsym, ScriptPosition); auto x = isclass ? new FxClassMember(object, vsym, ScriptPosition) : new FxStructMember(object, vsym, ScriptPosition);
object = nullptr; object = nullptr;
return x->Resolve(ctx); return x->Resolve(ctx);