[fpc-devel] specialization with type alias, bug or feature
Michael Van Canneyt
michael at freepascal.org
Thu Aug 17 20:08:10 CEST 2023
On Thu, 17 Aug 2023, Mattias Gaertner via fpc-devel wrote:
> FPC and Delphi handle type alias differently and I wonder if this was
> TMyDouble = type double;
> TBird<T> = class
> a: T;
> TDoubleBird = TBird<double>;
> TMyDoubleBird = TBird<TMyDouble>;
> Both FPC and Delphi create different classes for TDoubleBird and
> In Delphi they are not assign compatible, in FPC they are. For example:
> a: TDoubleBird;
> b: TMyDoubleBird;
> 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 ?
TArrayInteger1 = Array of Integer;
TArrayInteger2 = Array of Integer;
A1 : TArrayInteger1;
A2 : TArrayInteger2;
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
I am inclined to go for feature, but maybe there are arguments to tip the
balance in the direction of bug.
More information about the fpc-devel