From 12c10b5156b9ca8366d9b8e211e748012aba559a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 23 Jan 2019 00:05:10 +0100 Subject: [PATCH] - 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. --- src/scripting/backend/codegen.cpp | 44 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index aaf339c68..f8dd4c60b 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -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,29 +6058,36 @@ FxExpression *FxIdentifier::Resolve(FCompileContext& ctx) delete this; return 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))) + // 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) { - FxExpression *self = new FxSelf(ScriptPosition, true); - self = self->Resolve(ctx); - newex = ResolveMember(ctx, ctx.Class, self, ctx.Class); - ABORT(newex); - ScriptPosition.Message(MSG_OPTERROR, "Self pointer used in ambiguous context; VM execution may abort!"); - ctx.Unsafe = true; - goto foundit; - } - else - { - if (sym->IsKindOf(RUNTIME_CLASS(PFunction))) + // Do this check for ZScript as well, so that a clearer error message can be printed. MSG_OPTERROR will default to MSG_ERROR there. + if (ctx.Function->Variants[0].SelfClass != ctx.Class && sym->IsKindOf(RUNTIME_CLASS(PField))) { - ScriptPosition.Message(MSG_ERROR, "Function '%s' used without ().\n", Identifier.GetChars()); + FxExpression *self = new FxSelf(ScriptPosition, true); + self = self->Resolve(ctx); + newex = ResolveMember(ctx, ctx.Class, self, ctx.Class); + ABORT(newex); + ScriptPosition.Message(MSG_OPTERROR, "Self pointer used in ambiguous context; VM execution may abort!"); + ctx.Unsafe = true; + goto foundit; } else { - ScriptPosition.Message(MSG_ERROR, "Invalid member identifier '%s'.\n", Identifier.GetChars()); + 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; + } } - delete this; - return nullptr; } }