[fpc-devel] Another "bug or feature" type alias

Martin Frb lazarus at mfriebe.de
Tue Nov 3 10:24:52 CET 2026


Variables of non-related classes can't be assigned to each other.
E.g. wrong:
    f := b

type = type ...
creates a new type.
   TRec2 = type TRec;
then "r := r2" will not be allowed.

Do the same for classes.
   TFoo2 = type TFoo;
and
   f:= f2;
is not forbidden?



program Project1;
{$Mode objfpc}
type
   TRec = record a: integer; end;
   TRec2 = type TRec;

   TFoo = class a: integer; end;
   TFoo2 = type TFoo;

   TBar = class a: integer; end;

var
   r: TRec;
   r2: TRec2;
   f: TFoo;
   f2: TFoo2;
   b: TBar;
begin
   //r := r2;
   //f := b;
   f := f2;
   //(f as TBar).a := 1;
   (f as TFoo2).a := 1;
end.



More information about the fpc-devel mailing list