From 5e9001e7bc29c58249a3a7b522276b3f70a43134 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 1 Feb 2019 18:22:12 +0200 Subject: [PATCH] - fixed potentially incomplete list of argument flags for virtual function https://forum.zdoom.org/viewtopic.php?t=63450 --- src/scripting/zscript/zcc_compile.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 7d9ff78d8..b43057f16 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2767,6 +2767,8 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool } } + VMFunction *newfunc = nullptr; + if (!(f->Flags & ZCC_Native)) { if (f->Body == nullptr) @@ -2779,7 +2781,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool auto code = ConvertAST(c->Type(), f->Body); if (code != nullptr) { - FunctionBuildList.AddFunction(OutNamespace, mVersion, sym, code, FStringf("%s.%s", c->Type()->TypeName.GetChars(), FName(f->Name).GetChars()), false, -1, 0, Lump); + newfunc = FunctionBuildList.AddFunction(OutNamespace, mVersion, sym, code, FStringf("%s.%s", c->Type()->TypeName.GetChars(), FName(f->Name).GetChars()), false, -1, 0, Lump); } } } @@ -2859,6 +2861,16 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool sym->Variants[0].Implementation->DefaultArgs = parentfunc->Variants[0].Implementation->DefaultArgs; sym->Variants[0].ArgFlags = parentfunc->Variants[0].ArgFlags; } + + // Update argument flags for VM function if needed as their list could be incomplete + // At the moment of function creation, arguments with default values were not copied yet from the parent function + if (newfunc != nullptr && sym->Variants[0].ArgFlags.Size() != newfunc->ArgFlags.Size()) + { + for (unsigned i = newfunc->ArgFlags.Size(), count = sym->Variants[0].ArgFlags.Size(); i < count; ++i) + { + newfunc->ArgFlags.Push(sym->Variants[0].ArgFlags[i]); + } + } } } else