From 7a5171a2e92af33bc98a1beb97621f35516e05d6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 19:07:26 +0100 Subject: [PATCH] - fixed: The check for virtual function overrides was never done if the overriding function had no qualifier at all. - fixed several occurences where an 'override' qualifier was missing. --- src/scripting/zscript/zcc_compile.cpp | 10 +++++++++- wadsrc/static/zscript/heretic/hereticartifacts.txt | 2 +- wadsrc/static/zscript/heretic/weaponblaster.txt | 2 +- wadsrc/static/zscript/heretic/weaponphoenix.txt | 2 +- wadsrc/static/zscript/heretic/weaponskullrod.txt | 2 +- wadsrc/static/zscript/hexen/heresiarch.txt | 2 +- wadsrc/static/zscript/shared/setcolor.txt | 2 +- wadsrc/static/zscript/strife/weapongrenade.txt | 2 +- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 9684ec924..52cbc1d65 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2336,6 +2336,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool sym->Variants[0].Implementation->DefaultArgs = std::move(argdefaults); } + PClass *clstype = static_cast(c->Type()); if (varflags & VARF_Virtual) { if (sym->Variants[0].Implementation == nullptr) @@ -2349,7 +2350,6 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool } if (forclass) { - PClass *clstype = static_cast(c->Type()); int vindex = clstype->FindVirtualIndex(sym->SymbolName, sym->Variants[0].Proto); // specifying 'override' is necessary to prevent one of the biggest problem spots with virtual inheritance: Mismatching argument types. if (varflags & VARF_Override) @@ -2383,6 +2383,14 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool Error(p, "Virtual functions can only be defined for classes"); } } + else if (forclass) + { + int vindex = clstype->FindVirtualIndex(sym->SymbolName, sym->Variants[0].Proto); + if (vindex != -1) + { + Error(f, "Function %s attempts to override parent function without 'override' qualifier", FName(f->Name).GetChars()); + } + } } } diff --git a/wadsrc/static/zscript/heretic/hereticartifacts.txt b/wadsrc/static/zscript/heretic/hereticartifacts.txt index 20f52a2c9..3b7f14ad8 100644 --- a/wadsrc/static/zscript/heretic/hereticartifacts.txt +++ b/wadsrc/static/zscript/heretic/hereticartifacts.txt @@ -66,7 +66,7 @@ Class ArtiTomeOfPower : PowerupGiver Loop; } - bool Use (bool pickup) + override bool Use (bool pickup) { Playerinfo p = Owner.player; if (p && p.morphTics && (p.MorphStyle & MRF_UNDOBYTOMEOFPOWER)) diff --git a/wadsrc/static/zscript/heretic/weaponblaster.txt b/wadsrc/static/zscript/heretic/weaponblaster.txt index 913abffdb..e7e1e92b5 100644 --- a/wadsrc/static/zscript/heretic/weaponblaster.txt +++ b/wadsrc/static/zscript/heretic/weaponblaster.txt @@ -220,7 +220,7 @@ class Ripper : Actor Stop; } - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target is "Ironlich") { // Less damage to Ironlich bosses diff --git a/wadsrc/static/zscript/heretic/weaponphoenix.txt b/wadsrc/static/zscript/heretic/weaponphoenix.txt index eb75acb1d..558a257cd 100644 --- a/wadsrc/static/zscript/heretic/weaponphoenix.txt +++ b/wadsrc/static/zscript/heretic/weaponphoenix.txt @@ -311,7 +311,7 @@ class PhoenixFX2 : Actor } - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target.player && Random[PhoenixFX2]() < 128) { // Freeze player for a bit diff --git a/wadsrc/static/zscript/heretic/weaponskullrod.txt b/wadsrc/static/zscript/heretic/weaponskullrod.txt index a8d77e1d8..da959f7ae 100644 --- a/wadsrc/static/zscript/heretic/weaponskullrod.txt +++ b/wadsrc/static/zscript/heretic/weaponskullrod.txt @@ -402,7 +402,7 @@ class RainPillar : Actor // Rain pillar 1 ------------------------------------------------------------ - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target.bBoss) { // Decrease damage for bosses diff --git a/wadsrc/static/zscript/hexen/heresiarch.txt b/wadsrc/static/zscript/hexen/heresiarch.txt index 74bccbf4c..f89d2fb83 100644 --- a/wadsrc/static/zscript/hexen/heresiarch.txt +++ b/wadsrc/static/zscript/hexen/heresiarch.txt @@ -112,7 +112,7 @@ class Heresiarch : Actor Stop; } - void Die (Actor source, Actor inflictor, int dmgflags) + override void Die (Actor source, Actor inflictor, int dmgflags) { // The heresiarch just executes a script instead of a special upon death int script = special; diff --git a/wadsrc/static/zscript/shared/setcolor.txt b/wadsrc/static/zscript/shared/setcolor.txt index 18105ef54..2d9d3be57 100644 --- a/wadsrc/static/zscript/shared/setcolor.txt +++ b/wadsrc/static/zscript/shared/setcolor.txt @@ -28,7 +28,7 @@ class FadeSetter : Actor RenderStyle "None"; } - void PostBeginPlay() + override void PostBeginPlay() { Super.PostBeginPlay(); CurSector.SetFade(color(args[0], args[1], args[2])); diff --git a/wadsrc/static/zscript/strife/weapongrenade.txt b/wadsrc/static/zscript/strife/weapongrenade.txt index 7a775c57b..21e568313 100644 --- a/wadsrc/static/zscript/strife/weapongrenade.txt +++ b/wadsrc/static/zscript/strife/weapongrenade.txt @@ -241,7 +241,7 @@ class PhosphorousFire : Actor Stop; } - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target.bNoBlood) {