ZScript: "final" keyword

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!

ZScript: "final" keyword

Postby Player701 » Thu Nov 07, 2019 5:31 am

What exactly does "final" do in ZScript? For all this time, I simply assumed that it could be used on overridden methods so that they cannot be overridden again in subclasses. I never actually bothered to check, since I didn't try to override them myself, and the code compiled just fine. However, now that I've run some tests, it seems that this keyword does not actually do anything at all. Does anyone know what its true purpose is?

In gzdoom.pk3, this keyword is encountered only twice, both times in zscript/actors/doom/scriptedmarine.zs:

Code: Select allExpand view
final void SetWeapon (int type)
{
    ...
}

final void SetSprite (class<Actor> source)
{
    ...
}

This makes no sense to me, since even if I assume that "final" doesn't work due to a bug, there is no point in using it on non-virtual methods anyway (since they cannot be overridden in the first place). My only reaction to this as of now is "WTF?"...
User avatar
Player701
 
Joined: 13 May 2009
Location: Russian Federation
Discord: Player701#8214
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript: "final" keyword

Postby phantombeta » Thu Nov 07, 2019 6:20 am

It seems it was supposed to do that, but no one ever coded it to. Other code does implicitly mark things as non-overridable (specifically, static and action), and the code does seem to handle it, so why the "final" keyword doesn't actually mark things as non-overridable is probably a mystery.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript: "final" keyword

Postby Apeirogon » Thu Nov 07, 2019 6:29 am

According to definition, it must prevent virtual functions from overriding
https://github.com/coelckers/gzdoom/blo ... ypes.h#L23
And here is the confirmation
https://github.com/coelckers/gzdoom/blo ... .cpp#L2957

So.....its a bug and typo in scripted marines(functions was virtual before?)????
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: ZScript: "final" keyword

Postby Player701 » Thu Nov 07, 2019 7:01 am

OK, so I guess maybe this should be moved to Bugs... And since those two functions in ScriptedMarine are not virtual, "final" should be removed from there, and its use on non-virtual functions should probably be made a compiler error. Well, at least that's what I'd do...
User avatar
Player701
 
Joined: 13 May 2009
Location: Russian Federation
Discord: Player701#8214
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript: "final" keyword

Postby Graf Zahl » Thu Nov 07, 2019 8:48 am

This was once working, I can't say what broke it.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript: "final" keyword

Postby Rachael » Thu Nov 07, 2019 9:12 am

Player701 wrote:OK, so I guess maybe this should be moved to Bugs...

done
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: ZScript: "final" keyword

Postby phantombeta » Thu Nov 07, 2019 5:07 pm

Graf Zahl wrote:This was once working, I can't say what broke it.

It's not working because...
... There's no code for it. The token, modifier and compiler flag are defined, but it never sets the VARF_Final flag if the ZCC_Final modifier is set. Should be a trivial fix, I think.
I could definitely do it myself, but I'd need to know whether it should only be allowed on virtual functions first. IMO it should, but I think Graf should have the final say on that.

Btw, there's another modifier that's in the same situation as this one, "latent". But that one doesn't seem to have any backing flag in the compiler for it. I have the feeling it was something randi was planning for ZScript but you removed or something.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript: "final" keyword

Postby Graf Zahl » Thu Nov 07, 2019 5:17 pm

"Latent" was never implemented. One piece of trivia you should know is that the language was supposed to mimic UnrealScript, which is where this came from. But considering how the VM works, especially with a JIT in the game, this is a concept that's not really implementable anymore.

This isn't the only concept I removed. Another one was exceptions - but that put such an incredible drag on the VM that I decided early in the game not to pursue it. Even most experienced programmers I know have difficulties using exceptions right, no matter whether on Java, C++ or any other languages. ZDoom is really the only piece of software I know that uses exceptions properly, i.e. to report errors that need to be dealt with in a centralized spot. In basically all other cases they are the programming equivalentof a landmine and better avoided.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to Bugs

Who is online

Users browsing this forum: Apeirogon and 6 guests