Sign in Join

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

Mailing lists / fpc-pascal / 2025-05

Generics in current FPC trunk

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Thomas Kurz

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