ZDoom / gzdoom

GZDoom is a feature centric port for all Doom engine games, based on ZDoom, adding an OpenGL renderer and powerful scripting capabilities
http://zdoom.org
GNU General Public License v3.0
2.54k stars 552 forks source link

[BUG] [ZScript] "Invalid Scope for Function Pointer" in struct #2814

Open Player701 opened 2 days ago

Player701 commented 2 days ago

GZDoom version

4.13.2 and 4.14pre-76-gccd38afbc

Which game are you running with GZDoom?

Doom 2

What Operating System are you using?

Windows 11

Please describe your specific OS version

N/A

Relevant hardware info

N/A

Have you checked that no other similar issue already exists?

A clear and concise description of what the bug is.

This script works:

version "4.13"

class Test
{
    Function<play void()> f;
}

but change class to struct, and you get:

zscript.txt:zscript.txt, line 5: Invalid Scope for Function Pointer

Only clearscope seems to work; neither play nor ui does. Changing the scope of the struct itself to play or ui does not appear to have any effect either.

However, it is possible to work around this by declaring the type as Function<void>, but then a cast to the proper type will be necessary in order to call the function declared this way. Which makes me think this is likely a bug in the compiler and not some kind of fundamental limitation of the ZScript architecture.

Steps to reproduce the behaviour.

  1. Load the Zscript file provided in the description
  2. Observe that there is no error
  3. Change class to struct in the script code and try again
  4. Observe the error: "Invalid Scope for Function Pointer"

Your configuration

N/A

Provide a Log

N/A

RicardoLuis0 commented 2 days ago

hmm, that shouldn't be triggering at all since it's defined as play scope, is the parser doing something funky to struct members? https://github.com/ZDoom/gzdoom/blob/master/src/common/scripting/frontend/zcc_compile.cpp#L2072