sonar-openedge
sonar-openedge copied to clipboard
Rule idea: Setter should assign value locally
When reading
https://community.progress.com/s/article/4GL-ABL-Setting-a-property-as-an-output-parameter-inside-the-setter-block-causes-a-STOP-condition-and-the-client-crashes?popup=true
I thought this would be a good idea for a rule.
I reduced the attached sample code to a single failing class.
class IndefiniteSetter:
def public property a as longchar no-undo
get.
set (avalue as longchar):
Normalize(input avalue, output a). // endless loop here because a is used as output
end set.
method private void Normalize(input ivalue as longchar, output oresult as longchar):
oresult = ivalue.
end.
constructor public IndefiniteSetter():
a = "Set" .
end.
end class.
fix : Use an intermediate variable
def public property a as longchar no-undo
get.
set (avalue as longchar):
define variable lresult as longchar no-undo.
Normalize(input avalue, output lresult).
a = lres.
end set.