Re: [fpc-devel] specialization with type alias, bug or feature

2023-10-10 Thread Mattias Gaertner via fpc-devel



On 18.08.23 00:09, Mattias Gaertner via fpc-devel wrote:

[...]


Another point where it could wrong, is a generic method.
For example:

type
  TBird = class
    procedure Fly; // fpc does not yet allow this
  end;
var
  a: TBird;
  b: TBird;
begin
  a:=b;
  a.Fly; // this might call the wrong specialization or even call 
a non existing method

end;

So with class vars, generic methods and sub types the assignment must be 
forbidden.
Maybe pas2js could allow it for simple arrays, pointers, records and 
classes.


Mattias
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] specialization with type alias, bug or feature

2023-08-17 Thread Mattias Gaertner via fpc-devel



On 17.08.23 20:08, Michael Van Canneyt wrote:

[...]
Both FPC and Delphi create different classes for TDoubleBird and 
TMyDoubleBird.


In Delphi they are not assign compatible, in FPC they are. For example:
var
 a: TDoubleBird;
 b: TMyDoubleBird;
begin
 b:=TMyDoubleBird.Create;
 a:=b; // forbidden in Delphi
 writeln(a is TDoubleBird); // writes false

Bytewise the assignment is ok, but logic wise "a" is no longer a 
TDoubleBird.


Is this a bug or a feature?


Depends on how you look at it. Double and TMyDouble are assignment 
compatible.
There is no reason why the same should not hold true for TDoubleBird and 
TMyDoubleBird ?


I guess that is true for specialized arrays, records (non advanced), 
proc types and pointers, unless I forgot something (maybe helpers?).
But classes and interfaces have "is", "as", "class of", and "class 
vars", where the difference matter.





[...]
Of course, the method addresses are different. Other than that and the
different RTTI (which has 100% the same structure)


The different RTTI has 100% the same structure?
For clarification for others to follow the discussion here is an example:

type
  TBird = class(TPersistent)
  private
FWing: T;
  published
property Wing: T read FWing;
  end;

This is allowed in Delphi, but FPC refuses generic templates in published.
The TBird.Wing has a different PPropInfo than 
TBird.Wing. That is probably only relevant in some rare cases.




I am inclined to go for feature, but maybe there are arguments to tip the
balance in the direction of bug.


One point where it could wrong, is when you port Delphi code to FPC.
For example this is fine in Delphi:

type
  TBird = class
class var Cnt: integer;
  end;
  TDoubleBird = TBird;

procedure Fly(b: TDoubleBird);
begin
  inc(b.Cnt); // under Delphi this must be TBird.Cnt
// not so under FPC
  ...
  if TDoubleBird.Cnt=1 then ...
end;


Mattias

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] specialization with type alias, bug or feature

2023-08-17 Thread Michael Van Canneyt via fpc-devel




On Thu, 17 Aug 2023, Mattias Gaertner via fpc-devel wrote:


Hi,

FPC and Delphi handle type alias differently and I wonder if this was 
deliberate.


type
 TMyDouble = type double;

 TBird = class
   a: T;
 end;
 TDoubleBird = TBird;
 TMyDoubleBird = TBird;

Both FPC and Delphi create different classes for TDoubleBird and 
TMyDoubleBird.


In Delphi they are not assign compatible, in FPC they are. For example:
var
 a: TDoubleBird;
 b: TMyDoubleBird;
begin
 b:=TMyDoubleBird.Create;
 a:=b; // forbidden in Delphi
 writeln(a is TDoubleBird); // writes false

Bytewise the assignment is ok, but logic wise "a" is no longer a TDoubleBird.

Is this a bug or a feature?


Depends on how you look at it. Double and TMyDouble are assignment compatible.
There is no reason why the same should not hold true for TDoubleBird and 
TMyDoubleBird ?

In Delphi

Type
  TArrayInteger1 = Array of Integer;
  TArrayInteger2 = Array of Integer;

var
  A1 : TArrayInteger1;
  A2 : TArrayInteger2;

begin
  A1:=A2;
end.

Will not work, but in FPC it does. This is IMO similar.

Of course, the method addresses are different. Other than that and the
different RTTI (which has 100% the same structure) the classes are
identical. So based on that we could argue they are not assignment
compatible.

I am inclined to go for feature, but maybe there are arguments to tip the
balance in the direction of bug.

Michael.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] specialization with type alias, bug or feature

2023-08-17 Thread Mattias Gaertner via fpc-devel

Hi,

FPC and Delphi handle type alias differently and I wonder if this was 
deliberate.


type
  TMyDouble = type double;

  TBird = class
a: T;
  end;
  TDoubleBird = TBird;
  TMyDoubleBird = TBird;

Both FPC and Delphi create different classes for TDoubleBird and 
TMyDoubleBird.


In Delphi they are not assign compatible, in FPC they are. For example:
var
  a: TDoubleBird;
  b: TMyDoubleBird;
begin
  b:=TMyDoubleBird.Create;
  a:=b; // forbidden in Delphi
  writeln(a is TDoubleBird); // writes false

Bytewise the assignment is ok, but logic wise "a" is no longer a 
TDoubleBird.


Is this a bug or a feature?

Mattias
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel