Problem when using nested generic class descendant in a generic class method
Original Reporter info from Mantis: kyan
-
Reporter name: Constantine Yannakopoulos
Original Reporter info from Mantis: kyan
- Reporter name: Constantine Yannakopoulos
Description:
The following code produces a "Forward declaration not solved" error for every method of TInner<> generic class (Create and SomeError) if the TContainer<> class is specialized:
{$mode Delphi}{$H+}
type
TCustomInner<T> = class abstract
protected
function SomeMethod: T; virtual; abstract;
end;
TContainer<T> = class
public
function GetInner: TCustomInner<T>;
end;
TInner<T> = class(TCustomInner<T>)
private
FContainer: TContainer<T>;
protected
function SomeMethod: T; override;
public
constructor Create(AContainer: TContainer<T>);
end;
function TContainer<T>.GetInner: TCustomInner<T>;
type
InnerClass = TInner<T>;
begin
Result := InnerClass.Create(Self);
end;
function TInner<T>.SomeMethod: T;
begin
end;
constructor TInner<T>.Create(AContainer: TContainer<T>);
begin
FContainer := AContainer;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
C: TContainer<string>;
begin
C := TContainer<string>.Create;
end;
If TContainer<> is not specialized it compiles OK.
I don't know whether this is the recommended way to handle this case -especially the method implementation-level generic class alias- but it is the only way it compiles -at least until specialized.
Mantis conversion info:
- Mantis ID: 21051
- OS: Windows
- OS Build: 7 x64
- Platform: Win64
- Version: 2.7.1
- Fixed in version: 3.0.0
- Fixed in revision: 25577 (#68a38275)
- Monitored by: » jcchu (JC Chu), » kyan (Constantine Yannakopoulos), » arjument (Michael P. Qarakulow)