[fpc-pascal] Dynamic array bug

silvioprog silvioprog at gmail.com
Thu Nov 8 05:13:47 CET 2018


On Wed, Nov 7, 2018 at 11:06 PM Ryan Joseph <ryan at thealchemistguild.com>
wrote:

> I read the old thread and we need to add {$modeswitch arrayoperators} to
> make it work. a += [4] does work now.
>
> Also I found the thread where Sven said he fixed the "Incompatible types:
> got "Set Of Byte” bug in r39554 (
> https://bugs.freepascal.org/view.php?id=34021). It is indeed fixed but
> only for + operators.
>
> Do you want me to file a new bug report for := operators?


You can temporary solve it by specializing a generic array:

program project1;

{$mode objfpc}{$H+}
{$modeswitch advancedrecords}
{$modeswitch arrayoperators}

uses sysutils;

type
  TIntArray = specialize TArray<integer>;

  TMyRec = record
    a: TIntArray;
    class operator := (right: TIntArray): TMyRec;
  end;

class operator TMyRec.:= (right: TIntArray): TMyRec;
begin
  result.a := right;
end;

var
  r: TMyRec;
  a: TIntArray;
begin
  r := specialize TArray<integer>.Create(1, 2, 3);
  a := [1, 2, 3];
  a += [4];
end.

-- 
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20181108/50dede02/attachment.html>


More information about the fpc-pascal mailing list