Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2026-11

bug or feature? type alias

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

TFoo = type TBar

creates a new unique (non assignment compatible) type. At least for non-base types (e.g records).

In the below that works, except the new type is not entirely new. If the new type defines another type (nested), then that nested type is still compatible with the nested type of the original.

But non-commented assignments compile. (3.3.1)

Of course fields between the original and the alias are also assignment compatible.
So this may well be intended.

Just wanted to check.

program Project1;
{$Mode objfpc}
type
   TRec1 = record A: integer; end;
   TRec2 = type TRec1;
   TFoo1 = record
     a: integer;
     b: record x: integer; end;
   end;
   TFoo2 = type TFoo1;
   TBar1 = class
   public type
     Tbase = record A: integer; end;
     TInner = type TBase;
   end;
   TBar2 = type TBar1;
var
   r1: TRec1;
   r2: TRec2;
   f1: TFoo1;
   f2: TFoo2;
   i1: TBar1.TInner;
   i2: TBar2.TInner;
begin
   //r1 := r2;
   //f1 := f2;
   f1.b := f2.b;
   i1 := i2;
end.

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 8 lines
TFoo = type TBar creates a new unique (non assignment compatible) type. At least for non-base types (e.g records). In the below that works, except the new type is not entirely new. If the new type defines another type (nested), then that nested type is still compatible with the nested type of the original.

Yes. Delphi behaves the same.

Michael.

Reply by email