tw18096.pp 410 B

123456789101112131415161718192021222324
  1. { %fail }
  2. {$mode objfpc}
  3. type
  4. generic tc1<T> = class
  5. public
  6. x : T;
  7. end;
  8. generic tc2<T> = class
  9. type tc2a = specialize tc1<T>;
  10. var x : tc2a;
  11. end;
  12. tc2_Integer = specialize tc2<Integer>;
  13. var
  14. a : tc2_Integer;
  15. begin
  16. a := tc2_Integer.Create;
  17. a.x := tc2.tc2a.Create; // this is not allowed, user must use specialization of tc2
  18. a.x.x := 99;
  19. if (a.x.x <> 99) then
  20. Halt(1);
  21. end.