+2

[C108] "Nested With ..." does not detect some cases

Lübbe Onken 8 years ago updated 8 years ago 2

As I was playing around with C108, I came across the following code snippet, where FixInsight 2015.11upd2 does not detect the nested with statements.


program Project4;
{$APPTYPE CONSOLE}
{$R *.res}
type
  TA = class
    NA: string;
  end;
  TB = class
    NB: String;
  end;

var
  A: TA;
  B: TB;
begin
  A := TA.Create;
  B := TB.Create;

  with A, B do <-- would expect a C108 warning here. I consider this a "nested with" too
    WriteLn(NA, NB); 

  with A do
    with B do <-- would expect a C108 warning here
      WriteLn(NA, NB);

end.

Maybe it's fixed in a later version, but upd6 throws some false positives, which is why I won't roll it out in our company yet.

It does detect the second "with", when the code is copied into a .pas file. It doesn't detect the second with in a dpr as in the above example.

The first case:

  with A, B do <-- would expect a C108 warning here. I consider this a "nested with" too
    WriteLn(NA, NB); 

is unfortunately becoming important for us. We have installed a rule that fails the build when people add new nested with statements, but now, developers are smart ;), new
"with a,b do" 
statements creep into the code, which is not what we intend ...