Sign in Join

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

Mailing lists / fpc-pascal / 2013-04

Is this a bug?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Anthony Walter

I just wanted to get some opinions on this as to whether this is a bug. Generics in 2.7.x trunk allows units which use a generic class defined in another unit can access protected members.

Example:

unit A;
type
  TFoo<T> = class
  protected
    Bar: T;
  end;

<-- snip to next unit -->

unit B;
uses A;
Foo: TFoo<Integer>;
...
Foo.Bar := 42; // Code in unit B can access protected members of TFoo.

Should the above line generate a compiler error instead? That is ... TFoo.Bar shouldn't visible unless your code is in Unit A or in a method of a class which inherits TFoo<T>?

Sven Barth
to Anthony Walter
Anthony Walter wrote 28 lines
I just wanted to get some opinions on this as to whether this is a bug. Generics in 2.7.x trunk allows units which use a generic class defined in another unit can access protected members. Example: unit A; type TFoo<T> = class protected Bar: T; end; <-- snip to next unit --> unit B; uses A; Foo: TFoo<Integer>; ... Foo.Bar := 42; // Code in unit B can access protected members of TFoo. Should the above line generate a compiler error instead? That is ... TFoo.Bar shouldn't visible unless your code is in Unit A or in a method of a class which inherits TFoo<T>?

Delphi XE generates an error here, so this is indeed a bug. Would you please report it together with a complete example?

Regards,
Sven