0
Under review

W508 False positive when assigning to a property

dummzeuch 11 years ago updated 10 years ago 3
Assigning to a property might have side effects that make it necessary to make two successive assignment, e.g.:

procedure RestartTimer;
begin
FTimer.Enabled := False;
FTimer.Enabled := True;
end;

Difficult to determine whether this is a problem or not.
Maybe we could have a special comment like this:

// FixInsight:NoW512: duplicate assignment necessary
// ^- this part for FixInsight ^- This part for the developer

to get rid of these warnings once we have checked them?

So, this would no longer raise this warning:

procedure RestartTimer;
begin
// FixInsight:NoW512: duplicate assignment necessary
FTimer.Enabled := False;
FTimer.Enabled := True;
end;

Under review
You can use _FIXINSIGHT_ compiler directive. It works just like a real compiler conditional. For instance,
{$IFNDEF _FIXINSIGHT_}
procedure RestartTimer;
begin // this code will be ignored
FTimer.Enabled := False;
FTimer.Enabled := True;
end;
{$ENDIF}
This functionality is rather primitive though. It allows you to turn off any analysis, not only a single warning. A more comprehensive approach is still in the development. It will be available in future releases.
Also it may worth implementing some sort of exceptions... to ignore properties like Enabled or Active which are often used in this kind of assignments. What do you think about it?
No, no general exceptions. This is such a rare case that I think the programmers should take care of marking the exception. Also, it forces them to kind of document it.