Operator overloads see literal arrays as "Set of ..."
Original Reporter info from Mantis: CraigChapman
-
Reporter name: Craig Chapman
Original Reporter info from Mantis: CraigChapman
- Reporter name: Craig Chapman
Description:
Ref Issue 0034021
When overloading operators on records to assign arrays, literal arrays are mis-understood by the parser as "Set of &LtPos;type>"
This issue is reflected here:
https://bugs.freepascal.org/view.php?id=34021 and was already patched for the addition operator. However, the patch was specific to addition (nadd.pas modified). I am still seeing this issue for the assignment operator, as is demonstrated in the steps-to-reproduce. I have not tested subtraction, multiplication and division operators, but expect the issue to persist for those also.
Steps to reproduce:
program Project1;
{$mode objfpc}
{$modeswitch arrayoperators}
{$modeswitch advancedrecords}
type
MyRecord = record
private
fData: array of integer;
public
class operator:=(right: array of integer): MyRecord;
end;
class operator MyRecord.:= (right: array of integer): MyRecord;
var
idx: integer;
begin
if Length(right)<1 then begin
exit;
end;
SetLength(Result.fData,Length(right));
for idx := 0 to pred(Length(Result.fData)) do begin
Result.fData[idx] := right[idx];
end;
end;
var
aRec: MyRecord;
begin
aRec := [2,5]; //-< Compile-Time error "Incompatile types, got Set of Byte"
end.
Mantis conversion info:
- Mantis ID: 35061
- Build: r41244
- Version: 3.3.1
- Monitored by: » CraigChapman (Craig Chapman), » @genericptr (Ryan Joseph)