Why does not the compiler shows me the hint H2077 for variable s?

Why does not the compiler shows me the hint H2077 for variable s?

procedure Execute;
var
  s: string;
  i: Integer;
begin
  s := '';
  s := 'Foo';         // <-- No hints
  s := 'Hello World'; // <-- No hints
  i := 0;
  i := 2; // [DCC Hint] Project1.dpr(16): H2077 Value assigned to 'i' never used
  WriteLn(s, i);
end;

Comments

  1. Yes, for variable i I get a hint, but why not for the variable s?

    ReplyDelete
  2. I think 'cause the code is calling UStrClr and UStrLAsg and they are procedures and the compiler cannot check this condition.

    Same with Integer:

    procedure TestWithInteger;

      procedure MakeZero(var A: Integer);
      begin
        A := 0;
      end;

      procedure MakeOne(var A: Integer);
      begin
        A := 1;
      end;

    var
      I: Integer;
    begin
      MakeZero(I);
      MakeOne(I);
      WriteLn(I);
    end;

    ReplyDelete

Post a Comment