Question

I have a generic class in my project which has two overloaded methods with different visibility,as follows:

  • One with private visibility and some parameters. It uses the parameters and some private structures (some of which are injected in the constructor) to perform some operations.
  • A second one with protected visibility which is parameterless. This one is used by the derived classes to perform the operations implemented by the superclass. In order to do so it calls the private method .

This works fine but the compiler issues a hint message as follows:

[dcc32 Hint] Project1.dpr(15): H2219 Private symbol 'Bar' declared but never used

Out of curiosity I tried to recreate the class without it being a generic one. The compiler hint does not appear in that case.

Following you can find a simple example demonstrating the case:

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

type

  //class with generic type
  TFoo<T> = class
    private
      procedure Bar(param : string); overload;
    protected
      procedure Bar; overload;
  end;


  //class without generic type
  TFoo2 = class
    private
      procedure Bar(param : string); overload;
    protected
      procedure Bar; overload;
  end;

  //TFoo<T> methods
  procedure TFoo<T>.Bar(param: string);
  begin
    writeln('Foo<T>. this is a private procedure. ' + param);
  end;


  procedure TFoo<T>.Bar;
  begin
    writeln('Foo<T>. This is a protected procedure.');
    Bar('Foo<T>. calling from a protected one.');
  end;

  //TFoo2 methods
  procedure TFoo2.Bar(param: string);
  begin
    writeln('Foo2. this is a private procedure. ' + param);
  end;


  procedure TFoo2.Bar;
  begin
    writeln('Foo2. This is a protected procedure.');
    Bar('Foo2. calling from a protected one.');
  end;


var
  foo : TFoo<string>;
  foo2 : TFoo2;
begin
  try
    foo := TFoo<string>.Create;
    foo2 := TFoo2.Create;
    try
      foo.Bar;
      foo2.Bar;
      readln;
    finally
      foo.Free;
      foo2.Free;
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

In this example the generic type is not used, but it is not necessary to demonstrate the point. My real class does use it and the compiler hint also appears.

Any idea as to why this compiler hint appears for generic classes? I tested this on Delphi XE5.

Update: as it seems to be a compiler bug we have submitted a QC report.

Was it helpful?

Solution

It is a compiler bug. You should submit a QC report.

Interestingly your code does not even compile on older Delphi versions. For instance, I could not compile your code on XE3. The first call to Bar fails with:

[dcc32 Error]: E2250 There is no overloaded version of 'Bar' that can be called with these arguments

If I recall that problem is related to declaring and instantiating generic types in .dpr files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top