Reassignment to a method argument passed by value

objectscriptQuality release 
1.0.0
Id 
OS0052
Rule type 
Code Smell
Severity 

Major

Major
SQALE characteristic 
  • Reliability
    • Data
Tags 
coding-guidelines, probable-bug
Remediation function 
Constant/issue
Remediation cost 
15min

This rule detects when a method argument is reassigned in the method body but is not passed by reference.

Two possibilities exist:

This is done on purpose

While this is a distinct possibility, it is generally considered to be bad practice. It is advised that a dedicated variable be created for this purpose.

For instance, instead of doing:

    Method m(arg as %String) as %String
    {
        // modify arg, then...
        return arg
    }

write:

    Method m(arg as %String) as %String
    {
        #dim x as %String = arg
        // modify x, then...
        return x
    }

The argument was actually meant to be passed by reference

In this case, modify the prototype to add either the ByRef or Output modifier. For instance, replace:

    Method m(arg as %String)
    {
        // modify arg; modifications NOT visible by the caller
    }

with:

    Method m(ByRef arg as %String)
    {
        // modify arg; now modifications are visible by the caller
    }