[Issue 23259] Visibility entirely ignored by the compiler
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jul 19 11:18:02 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23259
--- Comment #2 from LucienPe <lucien.perregaux at gmail.com> ---
(In reply to LucienPe from comment #1)
> In fact, the bug has nothing to do with templates, the visibility is totally
> ignored :
>
> ```
> class C { private int h = 8; }
>
> void main()
> {
> C c = new C();
> writeln(c.h); // compiles
> }
> ```
Nevermind, the DIP states "Private class members are, technically, private
module members".
However, this example is still (in)valid :
main.d:
```
module main;
import c;
import std.stdio;
void main()
{
auto c = new C!string(8);
//writeln(c.h);
c.f!string(8);
}
```
c.d:
```
module c;
import std.stdio;
class C(T, Args...)
{
private:
this(int i, Args args)
{
string str = "private ctor should not be called !";
writeln(str);
//assert(0, str);
}
void f(U, V...)(int i, V v)
{
string str = "private function should not be called !";
writeln(str);
//assert(0, str);
}
public:
this(Args args)
{
writeln("public ctor should be called !");
}
void f(V...)(V v)
{
writeln("public function should be called !");
}
}
```
and produces:
```
private ctor should not be called !
private function should not be called !
```
--
More information about the Digitalmars-d-bugs
mailing list