summaryrefslogtreecommitdiff
path: root/tests/webtbf/tw35981.pp
blob: 06e1d1783cb708336a66946ee227563c1ab66072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{ %FAIL }

program tw35981;

{$mode Delphi}

uses Classes;

type
  TFoo<T: TPersistent> = class(TPersistent)
  public
    C: T;
    constructor Create;
    destructor Destroy; override;
  end;

  constructor TFoo<T>.Create;
  begin
    inherited Create;
    C := T.Create;
  end;

  destructor TFoo<T>.Destroy;
  begin
    C.Free;
    inherited Destroy;
  end;

  // note the *working* specialize here, in {$mode Delphi} !!!
  function Test<T: TPersistent>: specialize TFoo<T>;
  begin
    Result := TFoo<T>.Create;
  end;

begin
  with Test<TStrings> do begin
    WriteLn(C.ClassName);
    Free;
  end;
end.