[fpc-devel] Debug compiler

Ondrej Pokorny lazarus at kluug.net
Mon Nov 2 20:58:43 CET 2015


With pleasure :)

Yes it looks like if the parameter count matches, there is a compile 
error (correct). If it doesn't match (there are less or more 
parameters), it compiles (wrong).

Furthermore it doesn't only affect the getter but also the setter. All 
possible combinations compile. See attached project. I suspect the 
setter could be dangerous in connection to operator overloading.

Ondrej

-------------- next part --------------
program arraypropbug;

uses
  sysutils;

type
  TObj = class
  public
    function GetS(Index: Integer): string; overload;
    function GetS(Index1, Index2: Integer): Double; overload;
    procedure SetS(Index: Integer; const Str: string); overload;
    procedure SetS(Index: Integer; const Number: Double); overload;
    procedure SetS(Index1,  Index2: Integer; const Str: string); overload;
    procedure SetS(Index1,  Index2: Integer; const Number: Double); overload;
    property S[Index: Integer]: string read GetS write SetS;
  end;

{ TObj }

function TObj.GetS(Index1, Index2: Integer): Double;
begin
  Result := Index1 / Index2;
end;

function TObj.GetS(Index: Integer): string;
begin
  Result := IntToStr(Index);
end;

procedure TObj.SetS(Index1, Index2: Integer; const Number: Double);
begin

end;

procedure TObj.SetS(Index1, Index2: Integer; const Str: string);
begin

end;

procedure TObj.SetS(Index: Integer; const Number: Double);
begin

end;

procedure TObj.SetS(Index: Integer; const Str: string);
begin

end;

var
  o: TObj;
  s: string;
  d: Double;
begin
  o := TObj.Create;
  s := o.S[1];            // valid
  d := o.S[10, 3];        // !!!
  o.S[1] := 'string';     // valid
  o.S[1] := 11.9;         // !!!
  o.S[10, 3] := 'hello';  // !!!
  o.S[10, 3] := 15.4;     // !!!
end.



More information about the fpc-devel mailing list