Method argument not passed by reference

CachéQuality release 
1.0.0
Id 
OS0051
Rule type 
Severity 

Major

Major
SQALE characteristic 
  • Reliability
    • Data
Tags 
probable-bug
Remediation function 
Constant/issue
Remediation cost 
5min

In ObjectScript, you can declare arguments to be passed by reference, using either ByRef or Output modifiers, as in:

    ClassMethod m(ByRef x as %Integer)
    {
        // Actually modifies x for the caller
        set x = x + 1
    }

In callers, you then pass your arguments by reference using the unary dot operator, like so:

    // Assuming we are in the same class
    ClassMethod modifyByRef()
    {
        #dim x as %Integer
        set x = 1
        do ..m(.x) // note the dot
        // x is now 2
    }

However, not passing by reference will not raise an error, but the argument will then not be modified:

    // Assuming we are in the same class
    ClassMethod modifyByRefFailure()
    {
        #dim x as %Integer
        set x = 1
        do ..m(x) // NO DOT!
        // x is still 1
    }

This defeats the purpose of the argument being passed by reference in the method.

This either means that the method call misses the unary dot operator, or that the method prototype is wrong and that this argument was not meant to be passed by reference.

Whichever of the above is true, the code should be fixed to avoid this issue from being raised.