Skip to content

property getter does not call overridden getter in inherited class #10

Description

@User4martin

run to "write"

(pdr) p a
A = TFoo(@$00007F8180939060) { F_x: 42, F_y: 43, X: <getter: GetX>, Y: <getter: GetY> }
(pdr) p b
B = TBar(@$00007F8180939080) {  }
(pdr) p a.X
a.X = 42
(pdr) p a.Y
a.Y = 43
(pdr) p b.X
b.X = 42
(pdr) p b.Y
b.Y = 43
(pdr) inspect b
[INSPECT] b: TBar (class, 8 bytes)
[INSPECT] parent chain: TBar -> TFoo -> TObject

Not sure if intended? But b is empty / does not show contents of base class?

The important pant though:
b.Y should be 53

program project1;
{$Mode objfpc}
type

  { TFoo }

  TFoo = class
  private
    F_x, F_y: integer;
    function GetX: integer;
    function GetY: integer; virtual;
  public
    property X: integer read GetX;
    property Y: integer read GetY;
  end;

  { TBar }

  TBar = class(TFoo)
    function GetY: integer; override;
  end;

{ TBar }

function TBar.GetY: integer;
begin
  Result:= 10 + inherited GetY ;
end;

{ TFoo }

function TFoo.GetX: integer;
begin
  Result := F_x;
end;

function TFoo.GetY: integer;
begin
  Result := F_y;
end;

var a: TFoo; b: TBar;
begin
  a := TFoo.Create;
  a.F_x:=42;
  a.F_y:=43;
  b := TBar.Create;
  b.F_x:=42;
  b.F_y:=43;

write;
end.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions