13

Why is it that using generic types in a global procedure is not permitted. For example:

  procedure Foo<T>(bar : T);

Compiler Error: E2530 Type parameters not allowed on global procedure or function

Yet it is acceptable as a class method

TFoo = class(TObject)
public
  class procedure Foo<T>(bar : T);
end;

That's obviously my workaround, but I am interested in whether there an actual technical reason for the restriction.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Adam G
  • 1,283
  • 1
  • 6
  • 15
  • Any reason for the downvote? I am happy to edit my question if anything is unclear. – Adam G May 23 '18 at 06:38
  • 1
    Freepascal has support for global generic procedures/functions. – LU RD May 23 '18 at 07:38
  • Only the designers know the reason why this limitation exists. It is not documented, or publicly stated anywhere. And the main designer who could answer this definitively (Allen Bauer) is no longer with the company. – Remy Lebeau May 23 '18 at 15:34

1 Answers1

10

There is no technical reason why procedures at global scope could not be generic.

If the designers wanted to implement this, then it could be done.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Not sure why this would be downvoted, seeing as it's accurate, concise and answers the question. No pleasing some people, I guess. – MartynA May 23 '18 at 09:55
  • 1
    @MartynA Perils of answering a question which is probably closeable for being opinion based – David Heffernan May 23 '18 at 10:08
  • 5
    Well if it makes you feel any better, neither of your downvotes were from me. But I have no idea why you would think this opinion based. There is either a technical reason why it could not be done, or it wasn't done because they thought it bad/dangerous, or it wasn't done because they had other priorities. You are entirely free to be disinterested in the answer to this question, but I found it a curious omission and wondered whether it indicated something about the implementation of generics in Delphi that I was misunderstanding. In any case, thank you for your answer. – Adam G May 23 '18 at 10:58
  • @AdamG The question title, and the part of the body that I removed in my edit, are opinion based. And now I've edited out the opinion based part of the title. – David Heffernan May 23 '18 at 11:37