View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038363 | FPC | Compiler | public | 2021-01-16 17:39 | 2021-01-17 17:26 |
Reporter | Bart Broersma | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | new | Resolution | open | ||
Platform | i386 | OS | Windows | ||
Product Version | 3.3.1 | ||||
Summary | 0038363: Private fields of a generic class are accessible by specilized class. | ||||
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<T>=class private PrivateVar:T; end; TBarInt = specialize TBar<Integer>; implementation end.
| ||||
Additional Information | See: https://forum.lazarus.freepascal.org/index.php/topic,52883.0.html I was asked to report it here. | ||||
Tags | generics | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | |||||
Attached Files |
|
|
Attached test case. Please delete the contents of "Steps to reproduce", I only saw the extra line-endings once I posted. |
|
So why is this any different than creating a class without using generics in the same unit, you get visibility like you would otherwise ? I am not a generic lover myself due to how it uses resources (duplicates currently) But it is basically a template generation system and thus what ever unit you happen to specialize it in will be the same as if you manually created the class within the same unit, regardless where the declaration of the GENERIC is. I believe I have a pretty good understanding on the general GENERIC system which is most likely why I tried to avoid it. |
|
@jamie: Because the compiler is free to reuse a specialization from another unit if it's in scope to avoid duplication of binary code. This would lead to access to private fields failing to compile in some times depending on the units in the uses list. Delphi does not allow this either. The point is that the generic is part of the unit its declared in and thus the visibility rules of that unit need to be applied. |
Date Modified | Username | Field | Change |
---|---|---|---|
2021-01-16 17:39 | Bart Broersma | New Issue | |
2021-01-16 17:41 | Bart Broersma | Note Added: 0128370 | |
2021-01-16 17:41 | Bart Broersma | File Added: vis.zip | |
2021-01-16 18:00 | jamie philbrook | Note Added: 0128372 | |
2021-01-17 17:25 | Sven Barth | Note Added: 0128390 | |
2021-01-17 17:26 | Sven Barth | Tag Attached: generics |