Page MenuHomeFeedback Tracker

Request for Enscript behavior confirmation
New, UrgentPublic

Description

Please check if the following behavior is by design.

class ConflictClassDef
{
    int conflict = 111;

    void MethodDef(int conflict = 222, int conflictCheck = conflict)
    {
        Print(conflict);
        Print(conflictCheck);
    }
}
SCRIPT       : int conflict = 222
SCRIPT       : int conflictCheck = 222

I would have expected conflictCheck to be 111 as it should reference the class property and not the previously defined function.


If you swap the order it does not know the conflicting name yet and in this case, does not even attempt to use the class property and instead falls back to the default value.

class ConflictClassDef
{
    int conflict = 111;

    void MethodDef(int conflictCheck = conflict, int conflict = 222)
    {
        Print(conflict);
        Print(conflictCheck);
    }
}
SCRIPT       : int conflict = 222
SCRIPT       : int conflictCheck = 0

An easy "fix" if this is not intended would be to not allow non-compile-time constants as assignment expressions for parameters. That is what C# does.

Details

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

Please forward to the enfusion team for confirmation.

Event Timeline

interesting
double variable declaration
in class and in function
and no error?

No error, because the variable can exist in the global namespace, in the class as a field and inside a function both as a parameter and as a variable declared in the body.
That is alright in other languages as well. (C#)