Discussion:
[fpc-pascal] Dynamic array bug
Ryan Joseph
2018-11-07 04:12:49 UTC
Permalink
I finally built the trunk today (version 3.3.1) to try new dynamic array features and a bug fix Sven did a while ago but I’m still getting errors.

Did I get the wrong version or something? I thought these things were working now.

{$mode objfpc}
{$modeswitch advancedrecords}

program general;

type
TIntArray = array of 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 := [1, 2, 3]; // Incompatible types: got "Set Of Byte" expected "TMyRec"
a := [1, 2, 3];
a := a + [4]; // Operator is not overloaded: "{Dynamic} Array Of LongInt" + "Set Of Byte"
end.

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/f
silvioprog
2018-11-07 05:57:54 UTC
Permalink
Hi Ryan.
Post by Ryan Joseph
I finally built the trunk today (version 3.3.1) to try new dynamic array
features and a bug fix Sven did a while ago but I’m still getting errors.
Did I get the wrong version or something? I thought these things were working now.
Same problem here:

Error: Incompatible types: got "Set Of Byte" expected "TMyRec"
Error: Operator is not overloaded: "TIntArray" + "Set Of Byte"

It seems a bug, because the same code works fine on Delphi by changing
operator from ":=" to its respective name "Implicit".

My compiler ver: FPC 3.3.1 [2018/11/07] for x86_64 (Linux)

--
Silvio Clécio
Ryan Joseph
2018-11-07 06:07:22 UTC
Permalink
It seems a bug, because the same code works fine on Delphi by changing operator from ":=" to its respective name "Implicit”.
Good to know. I reported this before and Sven said it was fixed in an update (after another user had submitted the original patch).

Are you able to get a := a + [4]; to work? I’m looking Sven’s old message titled "Feature announcement: Dynamic array extensions” and he says + operator now works.

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/li
silvioprog
2018-11-07 14:31:41 UTC
Permalink
Post by Ryan Joseph
Good to know. I reported this before and Sven said it was fixed in an
update (after another user had submitted the original patch).
Are you able to get a := a + [4]; to work? I’m looking Sven’s old message
titled "Feature announcement: Dynamic array extensions” and he says +
operator now works.
Yes, it works. But only on Delphi:

a := a + [4];
writeln(a[3]); // prints 4
--
Silvio Clécio
Ryan Joseph
2018-11-07 14:35:31 UTC
Permalink
That’s too bad, I don’t use Delphi mode. Should be in Objfpc mode also right?

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.fre
silvioprog
2018-11-07 15:12:09 UTC
Permalink
That’s too bad, I don’t use Delphi mode. Should be in Objfpc mode also
right?
Oops... I meant "in Delphi compiler". ^^'

Anyway, it doesn't compile in FPC (tested in both delphi and objfpc modes).
--
Silvio Clécio
Ryan Joseph
2018-11-08 01:39:13 UTC
Permalink
Do you want me to file a new bug report for := operators?
I just filed a report just in case.

https://bugs.freepascal.org/view.php?id=34526

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/
silvioprog
2018-11-08 04:13:47 UTC
Permalink
I read the old thread and we need to add {$modeswitch arrayoperators} to
make it work. a += [4] does work now.
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
silvioprog
2018-11-08 04:17:01 UTC
Permalink
I read the old thread and we need to add {$modeswitch arrayoperators} to
make it work. a += [4] does work now.
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?
... or forcing the compiler to get the correct type by cast:

type
TIntArray = array of integer;

...

var
r: TMyRec;
begin
r := TIntArray([1, 2, 3]);
...

--
Silvio Clécio

Loading...