[fpc-devel] [] property overloads
Ben Grasset
operator97 at gmail.com
Tue Jul 9 22:09:00 CEST 2019
On Tue, Jul 9, 2019 at 3:17 PM Ryan Joseph <genericptr at gmail.com> wrote:
> Please post an example of the var/out bug if you don’t mind. Just to be
> sure.
>
I don't know if it necessarily *is* a bug.
It would definitely be if it worked with literals as input, which is the
impression I had based on what someone reported previously for some reason,
but again, after testing it myself that is not the case.
program Example;
{$mode ObjFPC}
{$modeswitch AdvancedRecords}
type
TRecord = record
private
function GetBoolOut(out Index: PtrUInt): Boolean;
function GetBoolVar(var Index: PtrUInt): Boolean;
public
property OutBools[out Index: PtrUInt]: Boolean read GetBoolOut;
property VarBools[var Index: PtrUInt]: Boolean read GetBoolVar;
end;
function TRecord.GetBoolOut(out Index: PtrUInt): Boolean;
begin
Result := Index > 5000;
end;
function TRecord.GetBoolVar(var Index: PtrUInt): Boolean;
begin
Result := Index > 5000;
end;
var
R: TRecord;
I: PtrUInt = 5000;
begin
// Error: Variable identifier expected
WriteLn(R.OutBools[5001]);
// Error: Variable identifier expected
WriteLn(R.VarBools[5001]);
// Works fine
WriteLn(R.OutBools[I]);
// Works fine
WriteLn(R.VarBools[I]);
end.
So the behavior as far as making sense based on the definition of "out" and
"var" is correct. The only thing that's really "strange" to me is the fact
that getters are completely unrestricted in that regard, while setters
explicitly need {$VARPROPSETTER ON}.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190709/34c8c333/attachment-0001.html>
More information about the fpc-devel
mailing list