Bug 23397 – private method callable from other module
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-10-08T20:11:33Z
Last change time
2022-10-10T03:33:14Z
Assigned to
No Owner
Creator
kdevel
Comments
Comment #0 by kdevel — 2022-10-08T20:11:33Z
Source: https://forum.dlang.org/thread/[email protected]
// file b.d
import std.stdio;
struct S {
private void foo (ubyte c)
{
writeln (__PRETTY_FUNCTION__);
}
void foo ()
{
}
}
// file a.d
unittest {
import b;
auto s = S ();
s.foo ('x');
}
$ dmd -g -unittest -main a.d b.d
$ ./a
void b.S.foo(ubyte c)
1 modules passed unittests
As Jack Pope pointed out in the forum reversing the order of definition of the methods of S gives in the expected behavior:
// file b.d (reversed order)
import std.stdio;
struct S {
void foo ()
{
}
private void foo (ubyte c)
{
writeln (__PRETTY_FUNCTION__);
}
}
$ dmd -g -unittest -main b.d -run a.d
a.d(5): Error: struct `b.S` function `foo` is not accessible
make: *** [run] Error 1
This seems to be a regression. 2.086.1 works as expected, 2.090.1 unexpectedly compiles the code. The versions inbetween I did not check.
Comment #1 by razvan.nitu1305 — 2022-10-10T03:33:14Z
*** This issue has been marked as a duplicate of issue 3254 ***