tw18096c.pp 630 B

12345678910111213141516171819202122232425262728293031
  1. { %fail }
  2. {$mode objfpc}
  3. type
  4. generic G<_T> = class
  5. end;
  6. generic TGen<_T> = class
  7. public
  8. function Check(ASource: TObject): Boolean;
  9. end;
  10. TSpec = specialize TGen<Integer>;
  11. function TGen.Check(ASource: TObject): Boolean;
  12. begin
  13. Result := not (ASource is G) // we are testing this: usage of another generic is not allowed
  14. and (ASource is TGen) // this should work...
  15. and (ASource is ClassType); // ...and it should be equivelent to this line
  16. end;
  17. var
  18. f: TSpec;
  19. o: TObject;
  20. begin
  21. f := TSpec.Create;
  22. o := TObject.Create;
  23. if not(f.Check(f)) or f.Check(o) then
  24. halt(1);
  25. writeln('ok');
  26. end.