Fix Issue 15371 - __traits(getMember) should bypass the protection

This commit is contained in:
RazvanN7 2019-04-10 15:46:15 +03:00
parent b21aa26a46
commit bd44bc789d
4 changed files with 37 additions and 2 deletions

11
changelog/traits.dd Normal file
View file

@ -0,0 +1,11 @@
Enable private member access for traits
The following traits can now access non-public members:
$(UL
$(LI getMember)
$(LI getOverloads)
)
This fixes a long-standing issue in D where the allMembers trait would correctly return non-public members but those non-public members would be inaccessible to other traits.
See BugZilla issue $(LINK2 https://issues.dlang.org/show_bug.cgi?id=15371, 15371)

View file

@ -887,9 +887,9 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
return new ErrorExp();
}
// ignore symbol visibility for these traits, should disable access checks as well
// ignore symbol visibility and disable access checks for these traits
Scope* scx = sc.push();
scx.flags |= SCOPE.ignoresymbolvisibility;
scx.flags |= SCOPE.ignoresymbolvisibility | SCOPE.noaccesscheck;
scope (exit) scx.pop();
if (e.ident == Id.hasMember)

View file

@ -0,0 +1,9 @@
module imports.test15371;
struct A
{
private int a;
private void fun() {}
private void fun(int, int) {}
public void fun(int) {}
}

View file

@ -0,0 +1,15 @@
/*
TEST_OUTPUT:
---
---
*/
import imports.test15371;
void main()
{
A a;
static assert(__traits(hasMember, A, "a"));
static assert(__traits(getOverloads, A, "fun").length == 3);
static assert(__traits(compiles, __traits(getMember, a, "a") ));
}