Declaration TFoo.Bar(AList: TList); and you call it this way: var LList: TList; begin TFoo.Bar(LList); end; so the compiler could know: ah, you mean TPersistent as T becaus LList is TList.
Fabian S. Biehn Exactly! Type inference only works if you got an argument of type T. But since the compiler has no information about LList being of a generic type at that point it is not possible currently (and most likely also not in the future which sucks)
Still a lot of compiler work to do (:
ReplyDeletetype
ReplyDeleteTFoo = class(TObject)
public
class procedure Bar;
end;
procedure TFoo.Bar;
begin
ShowMessage(T.ClassName());
end;
if i call TFoo.Bar>; which type should be used? I think it is working correct and persistent if the answer is TList and not TPersistent.
Fabian S. Biehn I guess you are not understanding what type inference is. Look it up on wikipedia.
ReplyDeleteGod yes I miss this so often coming from C++. Such a pain having to specify the types all day every day.
ReplyDeletehead -> table... aaaaaaaand repeat
ReplyDeletejust as my old teacher in school said... first read, than think, than write!
I tend to create a non-generic abstract class as the root class and use it as a type argument limiter as well.
ReplyDeleteLars Fosdal I guess you also miss the point.
ReplyDeleteEnlighten us simple folks, please?
ReplyDeleteMaybe you could then give us some simple example?
ReplyDeleteI think Stefan means this:
ReplyDeleteDeclaration TFoo.Bar(AList: TList); and you call it this way:
var
LList: TList;
begin
TFoo.Bar(LList);
end;
so the compiler could know: ah, you mean TPersistent as T becaus LList is TList.
Fabian S. Biehn Exactly! Type inference only works if you got an argument of type T. But since the compiler has no information about LList being of a generic type at that point it is not possible currently (and most likely also not in the future which sucks)
ReplyDeleteFabian S. Biehn indeed. I really miss this in Delphi.
ReplyDelete