0
Under review

[W513] False positives with numbered parameters

Anonymous 9 years ago updated by Lübbe Onken 9 years ago 6

Fixinsight 2015.11upd2


I didn't check all combinations, but I think that this example illustrates the problem


procedure TForm1.FormCreate(Sender: TObject);
var
  iError: integer;
  sError: string;
begin
  Format('Code %d [%s]', [iError, sError]);
  Format('Code %s [%s]', [sError, sError]);
  Format('Code %s [%d]', [sError, iError]);
  Format('Code %d [%d]', [iError, iError]);
  Format('Code %1:d [%2:s]', [iError, sError]); // <-- False positive
  Format('Code %1:s [%2:s]', [sError, sError]); // <-- False positive
  Format('Code %1:s [%2:d]', [sError, iError]); // <-- False positive
  Format('Code %1:d [%2:d]', [iError, iError]); // <-- False positive
end;

That was me, by the way. Forgot to sign in ...

Planned

I believe it worked before. Looks like a regression. I'll fix this ASAP.

Wait. Shouldn't it be %0:d and %1:d, but not 1 and 2?

Yes, you are right: The parameter numbers start with 0.

Under review

Sorry, my fault. And unfortunately the replies from userecho landed in my spam folder this weekend, which is why I didn't answer sooner.

I obviously made the error with index 1 and 2 instead of 0 and 1 and copied the error into the other rows when trying to figure out what went wrong. When I use 0 and 1, no false positives are shown.

But obviously the FI message could benefit from a little improvement. The number of parameters is correct, but the indexes are not. So it was no "false" positive, but a positive with a misleading message.


If you don't want to implement an extra warning, please consider changing the message to:

W513: "Format parameter count mismatch or index of parameter out of range"


Would it be possible for you to check the parameter types for compatibility? Because errors there will crash the applicaton at runtime.


Something like

var
  iError: integer;
  sError: string;
begin
  Format('Code %s [%d]', [sError, iError]);
  Format('Code %d [%d]', [iError, sError]); <-- Wxxx Parameter data type doesn't match placeholder
end;

Cheers & thanks