Dynamic array bug

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic array bug

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.

{$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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

silvioprog
Hi Ryan.

On Wed, Nov 7, 2018 at 1:13 AM Ryan Joseph <[hidden email]> wrote:
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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

Ryan Joseph


> On Nov 7, 2018, at 12:57 PM, silvioprog <[hidden email]> wrote:
>
> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

silvioprog
On Wed, Nov 7, 2018 at 3:39 AM Ryan Joseph <[hidden email]> wrote:
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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

Ryan Joseph

> On Nov 7, 2018, at 9:31 PM, silvioprog <[hidden email]> wrote:
>
> Yes, it works. But only on Delphi:
>

That’s too bad, I don’t use Delphi mode. Should be in Objfpc mode also right?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

silvioprog
On Wed, Nov 7, 2018 at 12:09 PM Ryan Joseph <[hidden email]> wrote:

> On Nov 7, 2018, at 9:31 PM, silvioprog <[hidden email]> wrote:
>
> Yes, it works. But only on Delphi:
>

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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

Ryan Joseph


> On Nov 7, 2018, at 10:12 PM, silvioprog <[hidden email]> wrote:
>
> Anyway, it doesn't compile in FPC (tested in both delphi and objfpc modes).
>

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?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

Ryan Joseph


> On Nov 8, 2018, at 8:35 AM, Ryan Joseph <[hidden email]> wrote:
>
> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

silvioprog
In reply to this post by Ryan Joseph
On Wed, Nov 7, 2018 at 11:06 PM Ryan Joseph <[hidden email]> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic array bug

silvioprog
On Thu, Nov 8, 2018 at 1:13 AM silvioprog <[hidden email]> wrote:
On Wed, Nov 7, 2018 at 11:06 PM Ryan Joseph <[hidden email]> 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:

... 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal