mirror of
https://github.com/dlang/dmd.git
synced 2025-04-29 14:40:12 +03:00
Fix Issue 15371 - __traits(getMember) should bypass the protection
This commit is contained in:
parent
b21aa26a46
commit
bd44bc789d
4 changed files with 37 additions and 2 deletions
11
changelog/traits.dd
Normal file
11
changelog/traits.dd
Normal 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)
|
|
@ -887,9 +887,9 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
|
||||||
return new ErrorExp();
|
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();
|
Scope* scx = sc.push();
|
||||||
scx.flags |= SCOPE.ignoresymbolvisibility;
|
scx.flags |= SCOPE.ignoresymbolvisibility | SCOPE.noaccesscheck;
|
||||||
scope (exit) scx.pop();
|
scope (exit) scx.pop();
|
||||||
|
|
||||||
if (e.ident == Id.hasMember)
|
if (e.ident == Id.hasMember)
|
||||||
|
|
9
test/compilable/imports/test15371.d
Normal file
9
test/compilable/imports/test15371.d
Normal 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) {}
|
||||||
|
}
|
15
test/compilable/test15371.d
Normal file
15
test/compilable/test15371.d
Normal 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") ));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue