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!
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

ZScript: "final" keyword

Post by Player701 »

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 all

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
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: ZScript: "final" keyword

Post by phantombeta »

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
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: ZScript: "final" keyword

Post by Apeirogon »

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?)????
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: ZScript: "final" keyword

Post by Player701 »

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: "final" keyword

Post by Graf Zahl »

This was once working, I can't say what broke it.
User avatar
Rachael
Posts: 13542
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: ZScript: "final" keyword

Post by Rachael »

Player701 wrote:OK, so I guess maybe this should be moved to Bugs...
done
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: ZScript: "final" keyword

Post by phantombeta »

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: "final" keyword

Post by Graf Zahl »

"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.
Post Reply

Return to “Bugs [GZDoom]”