Page MenuHomeFeedback Tracker

Enscript class member load order behavior
Reviewed, UrgentPublic

Description

I am not sure if a class should be allowed to compile like this, but right now it does.
When the variables are parsed and added to the parent class, their value expression is invoked. If it can not be invoked the variable gets it's default value.
Invoking functions works, no matter if the function is declared after it is used. This does not work for variables.

class TestBaseClass
{
    string m_Variable = m_Fnc();

    string m_Variable2 = m_Variable3;

    string m_Variable3 = "Hi there!";

    string m_Fnc()
    {
        return "Hello World";
    };
};

Produces:

SCRIPT       : string m_Variable = 'Hello World'
SCRIPT       : string m_Variable2 = ''
SCRIPT       : string m_Variable3 = 'Hi there!'

Swapping the load order to this:

class TestBaseClass
{
    string m_Variable = m_Fnc();

    string m_Variable3 = "Hi there!";

    string m_Variable2 = m_Variable3;

    string m_Fnc()
    {
        return "Hello World";
    };
};

Produces:

SCRIPT       : string m_Variable = 'Hello World'
SCRIPT       : string m_Variable2 = 'Hi there!'
SCRIPT       : string m_Variable3 = 'Hi there!'

The behavior is not surprising, given the way enscript currently works. What could be done is:

  1. Not allow non-const expressions as assignments for class field declarations
  2. Push variables, where the assingment expression could not be executed, due to unknown functions/variables, to a list and keep pushing it back until everything else is resolved. If all class members are loaded and it's still not resolved throw a compile error that says "unknown variable/function xxx on line x" to indicate that the line is faulty. Just ignoring the assignment expression (as it is right now) is not really verbose.

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Additional Information

Please forward this to the Enfusion team.

Event Timeline

Geez changed the task status from New to Assigned.Sep 14 2020, 1:26 PM
Geez changed the task status from Assigned to Reviewed.Sep 14 2020, 1:51 PM
Geez added a subscriber: Geez.

Hello Arkensor.
According to the Enf team this seems to be working as intended.
The example you have provided generates the following for them (This also seems to work in C++ the same way):

class TestBaseClass
{
    void TestBaseClass()
    {
        m_Variable = m_Fnc();
        m_Variable3 = "Hi there!";
        m_Variable2 = m_Variable3;
    }
    string m_Fnc()
    {
        return "Hello World";
    };
};

Regards,
Geez

Arkensor updated the task description. (Show Details)Sep 15 2020, 4:22 PM
Arkensor added a comment.EditedSep 15 2020, 4:37 PM

Hey @Geez

perhaps my report has been misread? I gave examples for both working and non-working. I have just run this code on the latest DayZ build.
It is simplified more. I was testing various things. For this issue we can boil it down to the following:

class TestBaseClass
{
    string m_Variable2 = m_Variable3;
    string m_Variable3 = "Hi there!";
};

void main()
{
    auto instance = new TestBaseClass();
    Print(instance.m_Variable2);
    Print(instance.m_Variable3);
}

Which produced this output:

---------------------------------------------
Log C:\Users\Arkensor\AppData\Local\DayZ\script_2020-09-15_16-25-36.log started at 15.09. 16:25:37

SCRIPT       : Registered 220 temporary action enum(s), UAN==220
SCRIPT       : CreateGame()
SCRIPT       : ... Backlit Effects Enabled
SCRIPT       : Loading Inc: 1
SCRIPT       : Creating Mission: .\Missions\EnscriptLanguage.ChernarusPlus\mission.c
SCRIPT       : SyncEvents -> RegisterEvents
SCRIPT       : string m_Variable2 = ''
SCRIPT       : string m_Variable3 = 'Hi there!'
SCRIPT       : Loading Inc: 1

The expected output would have been "Hi there!" for both m_Variable2 and m_Variable3 OR a compile error saying unknown variable m_Variable3 when trying to register m_Variable2.

Please let them redo the check on this example. I kind of doubt that they already fixed the issue on a later version of Enfusion.

Regards,
Paul