• Tracker

    Spaces
    Browse
    Statistics
  • /
  • /Stable Feedback
  • /DZG-1751
Back
15

Wrong compilation code

ServerClient
15

State

Assigned
Issue key
DZG-1751
Access
Public
Space
DayZ
Project
Stable Feedback
Creator
kgb
Created
Oct 21, 2026
Views
185
Platform
PC Steam
What happened?

incorrect compilation of scripts after 1.30

if in the client BSP there was code wrapped in #ifdef SERVER to use functions that are definitely present in another BSP of the same class, for example, it will not work, citing a missing function.

It has been noticed that the problem may occur depending on the order in which the mods are loaded.

Reproduction steps

Use code in client-side pbo:

Class TestClass_1
{
    void Precedure_1()
    {
        #ifdef SERVER
            Precedure_2();
        #endif
    }
}

then, use it at server side pbo

modded class TestClass_1
{
    void Precedure_2()
    {

    }
}


after server start - u can view compilation error -

Undefined function 'TestClass_1.Precedure_2' in client-side pbo
Exact build version (optional)
—
Where did it happen?
Official
Is it modded?
Yes
Expected result

the server starts, compiles the script correctly, finding the function wherever it is among the server mods.


before patch 1.30 everything worked correctly

Section
Mod list

-

Load order / launch params
—
Reactions

Activity

    about 1 month ago
  • kgb
    created issueabout 1 month ago
  • kgbcommented
    about 1 month ago
    kgbcommented
    about 1 month ago

    @l909 i think, problem like this - https://report.bistudio.com/issues/DZG-1145, but already connected with the division #ifdef / #ifndef

  • l909
    Moderator
    commented
    about 1 month ago
    l909
    Moderator
    commented
    about 1 month ago

    is it okay to close the ticket as a duplicate then?

  • kgbreplied to a comment(edited)
    about 1 month ago
    kgbreplied to a comment(edited)
    about 1 month ago

    I think this is related to the visibility of methods/variables under #ifdef / #ifndef, it's not exactly a duplicate

  • about 1 month ago
  • l909
    changed state to
    ASSIGNED
    about 1 month ago
  • 22 days ago
  • 6wingseraphcommented
    22 days ago
    6wingseraphcommented
    22 days ago

    @l909 hey, i've made an research on that:

    DayZServer_x64 1.30.164078, compared with 1.29.163709 (identical behaviour)

    Summary

    Not caused by #ifdef and not a 1.30 regression. Inside a modded class layer, an implicitthis call is resolved only from the current layer down to its bases, never up to the final class. Whether the code compiles therefore depends only on which of the two PBOs is loaded first.

    1. How modded classes are built

    For each modded class X the compiler renames the current X to X@<file>#<line>, makes the new layer derive from it, and rebinds the name X to the new layer. Result: one inheritance chain base -> layer1 -> ... -> top. The name X always means the top layer. A lower layer has no link to the layers above it.

    2. Where the call fails

    Precedure_2() without a receiver is compiled as a call on the current function's this, with no explicit class. The lookup class is the static type of this, i.e. the layer that owns the method body TestClass_1@441#1). The method lookup walks that class and its bases, then global functions. A method declared in a later layer is never found, so the compiler reports a hard error (not the FIX-ME warning path):

    Undefined function 'TestClass_1@441#1.Precedure_2'

    Member variables behave the same: Can't find variable 'm_Var'.

    3. Why it depends on load order

    Layer order = CfgMods order = config load order. PBOs are sorted by prefix (case-insensitive); then a dependency pass emits each addon once its requiredAddons are loaded. Command-line order and -mod vs -serverMod do not matter. The code compiles only if the server PBO happens to load before the client PBO; changing a prefix or adding one requiredAddons entry flips it. Same algorithm and same results in 1.29.163709 and 1.30.164078.

    4. The call itself is valid

    In the failing order (client layer below the server layer), this compiles on 1.30.164078 and calls the server-side method at runtime:

    TestClass_1.Cast(this).Precedure_2();

    The same works for a field added by the upper layer. The name TestClass_1 already resolves to the top layer while the lower layer's body is compiled, and at runtime this is always an instance of the top layer.

    5. Suggested fix (small, local, backward compatible)

    In the call compiler, where the method lookup on the class of this fails, before reporting "Undefined function":

    - if the call has no explicit receiver (implicit this, or this.) and the class of this is a renamed modded layer,

    - repeat the lookup on the top layer (the class currently bound to the original name),

    - if found, compile the call as on Cast(this) to the top layer: a normal virtual call on this.

    Apply the same fallback to member variable lookup ("Can't find variable"). Code that compiles today is unaffected, because the fallback only replaces an error. If a lower-layer type can be instantiated through reflection, use a checked (null-safe) cast for the fallback call.

    Changing the load order (e.g. loading -serverMod first) would not fix it: it only changes which pattern fails.

    Workaround for current builds:

    TestClass_1.Cast(this).Precedure_2();

    or an empty hook in the client layer, override in the server layer, and the client CfgPatches in the server's requiredAddons.

You are not signed in. Please sign in to see more details and to reply.

State

Assigned
Issue key
DZG-1751
Access
Public
Space
DayZ
Project
Stable Feedback
Creator
kgb
Created
Oct 21, 2026
Views
185