[Issue 23907] New: __traits(child) respects visibility
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 8 16:31:32 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23907
Issue ID: 23907
Summary: __traits(child) respects visibility
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: qs.il.paperinik at gmail.com
The `child` trait is a reflection tool. It should **not** respect visibility
(in the second parameter, i.e. the alias of a member function). If respecting
visibility is desired, `getVisibility` can be used. This is consistent with
other reflection traits, the reason being that a library that uses reflection
may be passed a private symbol in the module in which it is defined.
Visibility is (correctly) bypassed when the address of the expression is taken.
Example (suitable for run.dlang.io):
```d
--- a.d
module a;
struct S
{
private void f(int i)
{
import std.stdio;
writeln("S.f(", i, ")");
}
}
alias publicAlias = S.f;
--- playground.d
#line 17 "playground.d"
import a;
void main()
{
S s;
s.f(0); // okay: fails because `f` is private
__traits(child, s, publicAlias)(42); // bug: fails
(&__traits(child, s, publicAlias))(42); // okay
}
```d
--
More information about the Digitalmars-d-bugs
mailing list