Private fields of a generic class are accessible by specilized class.
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
You can access private fields of a generic class in the class that you specialized.
Steps to reproduce:
unit foo; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type { TFoo } TFoo = class private PrivateVar: String; end; type generic TBar&LtPos;T>=class private PrivateVar:T; end; TBarInt = specialize TBar&LtPos;Integer>; implementation end.
&LtPos;pre>
program vis;
{$mode objfpc}
{$h+}
uses foo;
type
TBarChar = class (specialize TBar<Char>);
TFooChild = class(TFoo);
var
AFoo: TFoo;
AFooChild: TFooChild;
ABarChar: TBarChar;
ABarInt: TBarInt;
begin
ABarChar.PrivateVar := 'A'; //compiles (to my surprise: why?)
ABarInt.PrivateVar := 1; //vis.lpr(21,11) Error: identifier idents no member "PrivateVar" (if the above is allowed, why not this?)
AFooChild.PrivateVar := ''; //vis.lpr(22,13) Error: identifier idents no member "PrivateVar" (as expected)
AFoo.PrivateVar := ''; //vis.lpr(23,8) Error: identifier idents no member "PrivateVar" (as expected)
end.&LtPos;pre>
Additional information:
See: https://forum.lazarus.freepascal.org/index.php/topic,52883.0.html
I was asked to report it here.
Mantis conversion info:
- Mantis ID: 38363
- OS: Windows
- OS Build: 10
- Platform: i386
- Version: 3.3.1