Extending classes doesn't work with nested #includes

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
Xeotroid
Posts: 392
Joined: Sat Jun 23, 2012 7:44 am
Graphics Processor: nVidia with Vulkan support
Location: Czech Rep.

Extending classes doesn't work with nested #includes

Post by Xeotroid »

I'm using a ZScript library that comes with its own file full of #includes. I wanted to extend one of its classes so that updating the library wouldn't cause issues. I put my extensions into a separate file and #include it after the library. However, I receive an error that the class to be extended could not be found in the current translation unit.

This approach doesn't work:
Main ZScript file:

Code: Select all

#include "library/includes.zs"
#include "zscript/extensions.zs"
includes.zs:

Code: Select all

#include "library/library.zs"
Including library.zs directly in the main ZS file (omitting the library's includes file) works fine:

Code: Select all

#include "library/library.zs"
#include "zscript/extensions.zs"
For the modder it's easy to just put all #includes into one file, so the severity of this is more or less zero, and a fix doesn't sound worth the trouble (how often do you access your main ZScript file?), but I couldn't find a mention of this. Should it be clarified in the wiki article for future reference?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48376
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Extending classes doesn't work with nested #includes

Post by Graf Zahl »

That's due to how includes get processed in ZScript. This is not a preprocessor that pulls in the text. It merely adds the file to the end of the list of script files to compile.

What this means is that your files get processed in the wrong order, as
#include "zscript/extensions.zs"
gets parsed before
#include "library/library.zs"

and therefore compiled before the library. This is a technical limitation of how the compiler works so it's not really fixable.

Return to “Bugs [GZDoom]”