Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Language/Overloading/Method    [ Add a report in this area ]  
Report #:  16089   Status: Open
Covariant Returns
Project:  Delphi Build #:  9
Version:    9.0 Submitted By:   Gideon Sireling
Report Type:  Suggestion / Enhancement Request Date Reported:  9/20/2005 2:39:28 AM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   257097
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (4 Total Ratings)
4.00 out of 5
Total Votes: 30
Description
An overriding method should be able to declare a return type which descends from the return type of the overriden method.

See Steps for a simplified example.

More thorough example (using C#):
http://blogs.msdn.com/cyrusn/archive/2004/12/08/278661.aspx
Steps to Reproduce:
type
  TFood = class
  end;

  TWine = class(TFood)
  end;

  TServer = class
    function Serve: TFood; virtual;
  end;

  TButler = class(TServer)
    function Serve: TWine; override; //Covariant return instead of TFood
  end;

function TServer.Serve: TFood;
begin
  Serve := TFood.Create;
end;

function TButler.Serve: TWine;
begin
  Serve := TWine.Create;
end;
Workarounds
None
Attachment
None
Comments

Rob Kennedy at 10/5/2005 8:34:12 PM -
This report would be better if it described what it is it's requesting. It should have a description of what it means to support covariant return types. I know what they are, and the relevant people at Borland should know what they are, but not everyone does, and people won't vote for feature requests they don't understand.

Also, this report could stand to have a better example. The one with THTTPSSession just looks like it's a typo with an extra S. Provide something that better illustrates what covariant returns are. Also, describe some cases for why it would be useful.

Server Response from: ETNACODE01