From 6bc82bdeff7d6cf653b2d20c607ef3cb12c12952 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 4 Feb 2021 12:00:06 +0200 Subject: [PATCH] - fixed incorrect extension of overridden function prototype Prototype of overridden function with optional argument(s) missing could extend unrelated prototype of previously defined function when their arguments and return value(s) match https://forum.zdoom.org/viewtopic.php?t=71340 --- src/common/objects/dobjtype.cpp | 8 ++++++-- src/common/scripting/frontend/zcc_compile.cpp | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/objects/dobjtype.cpp b/src/common/objects/dobjtype.cpp index 03a1cc980..b74820ed4 100644 --- a/src/common/objects/dobjtype.cpp +++ b/src/common/objects/dobjtype.cpp @@ -706,13 +706,17 @@ int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction if (!(parentfunc->Variants[0].ArgFlags[a] & VARF_Optional)) return -1; } - // Todo: extend the prototype + // Extend the prototype + TArray argumentTypes = proto->ArgumentTypes; + for (unsigned a = proto->ArgumentTypes.Size(); a < vproto->ArgumentTypes.Size(); a++) { - proto->ArgumentTypes.Push(vproto->ArgumentTypes[a]); + argumentTypes.Push(vproto->ArgumentTypes[a]); variant->ArgFlags.Push(parentfunc->Variants[0].ArgFlags[a]); variant->ArgNames.Push(NAME_None); } + + variant->Proto = NewPrototype(proto->ReturnTypes, argumentTypes); } return i; } diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index 1acd9899a..07c4fe346 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -2486,6 +2486,8 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool { newfunc->ArgFlags.Push(sym->Variants[0].ArgFlags[i]); } + + newfunc->Proto = sym->Variants[0].Proto; } } }