property getter wrongly allowed to have default values in params: Foo: Boolean = True
Original Reporter info from Mantis: Martin @martin_frb
-
Reporter name: Martin Friebe
Original Reporter info from Mantis: Martin @martin_frb
- Reporter name: Martin Friebe
Description:
See the Unit in added info. (It's the relevant fragments from a lazarus Form)
It compiles without error.
however allowing a property getter to have optional parameters (and hence the property to have optional amount of indexes, does conflict with setters. Setters can not have this.
this should probably not be allowed
----
I believe properties with a getter a often just translated into a function/procedure call, without any checking before?
At least there are various cases where erroneous property use causes errors referring to the underlying function.
If for example you remove the default value from the getter, so that it must have both values specified
function GetFoo(Index: Integer; Ask: Boolean = True): Integer;
and call
Foo[1] // with one arg missing.
you get the error
unit1.pas(33,22) Error: Wrong number of parameters specified for call to "GetFoo"
Which is annoying in so far, as you don't actually see GetFoo in the source at the given location.
Additional information:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs;
type
{ TForm1 }
TForm1 = class(TForm)
private
function GetFoo(Index: Integer; Ask: Boolean = True): Integer;
public
property Foo[Index: Integer; Ask: Boolean]: Integer read GetFoo;
end;
implementation
function TForm1.GetFoo(Index: Integer; Ask: Boolean): Integer;
begin
Result := Foo[Index];
end;
end.
Mantis conversion info:
- Mantis ID: 13956
- Version: 2.2.4
- Fixed in version: 2.4.0
- Fixed in revision: 13326 (#e42842b3)