The following traits can now access non-public members:
- hasMember
- getMember
- getOverloads
- getVirtualMethods
- getVirtualFuntions
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.
Reviewed-on: https://github.com/dlang/dmd/pull/12135
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd
3a7ebef73.
-2d3d137489f030395d06cb664087fd1a35bccabe
+3a7ebef73cc01d4a877a95cf95cd3776c9e3ee66
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
+ // ignore symbol visibility and disable access checks for these traits
+ Scope *scx = sc->push();
+ scx->flags |= SCOPEignoresymbolvisibility | SCOPEnoaccesscheck;
+
if (e->ident == Id::hasMember)
{
/* Take any errors as meaning it wasn't found
*/
if (e->ident == Id::hasMember)
{
/* Take any errors as meaning it wasn't found
*/
- Scope *scx = sc->push();
- scx->flags |= SCOPEignoresymbolvisibility;
ex = trySemantic(ex, scx);
scx->pop();
return ex ? True(e) : False(e);
ex = trySemantic(ex, scx);
scx->pop();
return ex ? True(e) : False(e);
if (ex->op == TOKdotid)
// Prevent semantic() from replacing Symbol with its initializer
((DotIdExp *)ex)->wantsym = true;
if (ex->op == TOKdotid)
// Prevent semantic() from replacing Symbol with its initializer
((DotIdExp *)ex)->wantsym = true;
- Scope *scx = sc->push();
- scx->flags |= SCOPEignoresymbolvisibility;
ex = semantic(ex, scx);
scx->pop();
return ex;
ex = semantic(ex, scx);
scx->pop();
return ex;
{
unsigned errors = global.errors;
Expression *eorig = ex;
{
unsigned errors = global.errors;
Expression *eorig = ex;
- Scope *scx = sc->push();
- scx->flags |= SCOPEignoresymbolvisibility;
ex = semantic(ex, scx);
if (errors < global.errors)
e->error("%s cannot be resolved", eorig->toChars());
ex = semantic(ex, scx);
if (errors < global.errors)
e->error("%s cannot be resolved", eorig->toChars());
--- /dev/null
+module imports.test15371;
+
+struct A
+{
+ private int a;
+ private void fun() {}
+ private void fun(int, int) {}
+ public void fun(int) {}
+}
--- /dev/null
+// EXTRA_FILES: imports/test15371.d
+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") ));
+}