[fpc-pascal] Generics in current FPC trunk

Thomas Kurz fpc.2021 at t-net.ruhr
Sat May 24 20:54:33 CEST 2025


Hello,

I have noticed, that this construct fails in current trunk version:

unit a;
type generic TFoo<T> = record
  privat FField: integer;
end;

unit b;
type TBar = specialize TFoo<Bar>;
type TBarHelper = type helper for TBar
  procedure DoSomething;
end;

procedure TBarHelper.DoSomething;
begin
  FField := 0;   // <-- access to `private` field forbidden due to different unit
end;

So, in the specialized record, private fields are no longer accessible. This used to work some time ago (about 1 year). I do fully understand that it is forbidden, because it's the way "private" is meant to be.

However, I'd like to ask whether this behavior change is intentional or a regression. If it's intentional, we need `protected` fields in records, too, imho. Otherwise, there'd be no way to access a private field in a specialized type if it has been defined in the generic type. And there may be good reasons not to make it public.

Kind regards,
Thomas



More information about the fpc-pascal mailing list