See the below code. (tested 3.2.3 and 3.3.1)

Is this intentionally allowed?

Technically it should work. TSubTest.Test always returns something that fits the inherited requirement.


program Project1;
type
  TFoo = class end;
  TBar = class(TFoo) end;

  TTest = class
    function Test: TFoo; virtual; abstract;
  end;

  TSubTest = class(TTest)
    function Test: TBar; override;
  end;

function TSubTest.Test: TBar;
begin  end;

begin  end.


And if that is intentional, then why not also

  TTest = class
    procedure Test(a: TBar); virtual; abstract;
  end;

  TSubTest = class(TTest)
    procedure Test(a: TFoo); override;
  end;

This fails. Even though any TBar passed will be fine to the base and the subclass.

And any
  var sub: TSubTest
will accept TFoo too, but such a var can never hold the base class.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to