Skip to content

Commit

Permalink
Fix Issue 21936 - Segfault with -dip1000
Browse files Browse the repository at this point in the history
  • Loading branch information
UplinkCoder authored and dlang-bot committed May 21, 2021
1 parent fea011e commit 4ce4209
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/dmd/access.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ bool checkAccess(AggregateDeclaration ad, Loc loc, Scope* sc, Dsymbol smember)
return false; // for backward compatibility
}

if (!symbolIsVisible(sc, smember) && (!(sc.flags & SCOPE.onlysafeaccess) || sc.func.setUnsafe()))
if (!symbolIsVisible(sc, smember))
{
// when in @safe code or with -preview=dip1000
if (sc.flags & SCOPE.onlysafeaccess)
{
// if there is a func. ask for it's opinion of safety, and if it considers the access @safe accept it.
if (sc.func && !sc.func.setUnsafe())
return false;
}

ad.error(loc, "member `%s` is not accessible%s", smember.toChars(), (sc.flags & SCOPE.onlysafeaccess) ? " from `@safe` code".ptr : "".ptr);
//printf("smember = %s %s, vis = %d, semanticRun = %d\n",
// smember.kind(), smember.toPrettyChars(), smember.visible() smember.semanticRun);
Expand Down
4 changes: 4 additions & 0 deletions test/fail_compilation/imports/issue21936s.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct S
{
private int field;
}
32 changes: 32 additions & 0 deletions test/fail_compilation/issue21936.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* REQUIRED_ARGS: -preview=dip1000 -Ifail_compilation/imports
TEST_OUTPUT:
---
fail_compilation/issue21936.d(15): Error: struct `issue21936s.S` member `field` is not accessible from `@safe` code
fail_compilation/issue21936.d(15): Error: struct `issue21936s.S` member `field` is not accessible from `@safe` code
fail_compilation/issue21936.d(11): Error: template instance `issue21936.constructImplicit!(S)` error instantiating
fail_compilation/issue21936.d(7): instantiated from here: `registerConstructors!(S)`
fail_compilation/issue21936.d(21): instantiated from here: `registerType!(S)`
---
*/
#line 2
module issue21936;
import issue21936s;
struct Handlers {
void registerType(T)()
{
registerConstructors!T;
}
void registerConstructors(T)()
{
constructImplicit!T;
}
}

auto constructImplicit(T)(typeof(T.init.tupleof) x = T.init.tupleof)
{
}

void registerHandlersDateTime(Handlers handlers)
{
handlers.registerType!(S);
}

0 comments on commit 4ce4209

Please sign in to comment.