I wish type inference would not only work for arguments of the type T but also for (arguments of) generic types of T.

Comments

  1. type
      TFoo = 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.

    ReplyDelete
  2. Fabian S. Biehn I guess you are not understanding what type inference is. Look it up on wikipedia.

    ReplyDelete
  3. God yes I miss this so often coming from C++. Such a pain having to specify the types all day every day.

    ReplyDelete
  4. head -> table... aaaaaaaand repeat
    just as my old teacher in school said... first read, than think, than write!

    ReplyDelete
  5. I tend to create a non-generic abstract class as the root class and use it as a type argument limiter as well.

    ReplyDelete
  6. Lars Fosdal I guess you also miss the point.

    ReplyDelete
  7. Enlighten us simple folks, please?

    ReplyDelete
  8. Maybe you could then give us some simple example?

    ReplyDelete
  9. I think Stefan means this:

    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.

    ReplyDelete
  10. 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)

    ReplyDelete
  11. Fabian S. Biehn indeed. I really miss this in Delphi.

    ReplyDelete

Post a Comment