- fixed Identifier resolving for static functions

This entered the code path which warned about ambiguous use of variables in action functions and as a result ran afoul of subsequent error checks.

Since ZScript has no global scope resolution operator, this needs to ignore all non-static class symbols and try to look up any of these as global identifiers.
This commit is contained in:
Christoph Oelckers 2019-01-23 00:05:10 +01:00
parent 6a9322e677
commit 12c10b5156

View file

@ -6031,11 +6031,10 @@ FxExpression *FxIdentifier::Resolve(FCompileContext& ctx)
{
if (ctx.Function == nullptr)
{
ScriptPosition.Message(MSG_ERROR, "Unable to access class member %s from constant declaration", sym->SymbolName.GetChars());
ScriptPosition.Message(MSG_ERROR, "Unable to access class member %s from constant declaration", Identifier.GetChars());
delete this;
return nullptr;
}
FxExpression *self = new FxSelf(ScriptPosition);
self = self->Resolve(ctx);
newex = ResolveMember(ctx, ctx.Function->Variants[0].SelfClass, self, ctx.Function->Variants[0].SelfClass);
@ -6059,8 +6058,12 @@ FxExpression *FxIdentifier::Resolve(FCompileContext& ctx)
delete this;
return nullptr;
}
// The following only applies to non-static content.
// Static functions have no access to non-static parts of a class and should be able to see global identifiers of the same name.
else if (ctx.Function->Variants[0].SelfClass != nullptr)
{
// Do this check for ZScript as well, so that a clearer error message can be printed. MSG_OPTERROR will default to MSG_ERROR there.
else if (ctx.Function->Variants[0].SelfClass != ctx.Class && sym->IsKindOf(RUNTIME_CLASS(PField)))
if (ctx.Function->Variants[0].SelfClass != ctx.Class && sym->IsKindOf(RUNTIME_CLASS(PField)))
{
FxExpression *self = new FxSelf(ScriptPosition, true);
self = self->Resolve(ctx);
@ -6075,15 +6078,18 @@ FxExpression *FxIdentifier::Resolve(FCompileContext& ctx)
if (sym->IsKindOf(RUNTIME_CLASS(PFunction)))
{
ScriptPosition.Message(MSG_ERROR, "Function '%s' used without ().\n", Identifier.GetChars());
delete this;
return nullptr;
}
else
{
ScriptPosition.Message(MSG_ERROR, "Invalid member identifier '%s'.\n", Identifier.GetChars());
}
delete this;
return nullptr;
}
}
}
}
if (noglobal)
{