Skip to content

Commit

Permalink
fix Issue 7475 - Regression(2.058 beta): Template member erroneously …
Browse files Browse the repository at this point in the history
…inaccessible
  • Loading branch information
WalterBright committed Feb 10, 2012
1 parent 7b3d07a commit c504c3f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
30 changes: 12 additions & 18 deletions src/access.c
Expand Up @@ -265,7 +265,7 @@ int AggregateDeclaration::isFriendOf(AggregateDeclaration *cd)

// Friends if both are in the same module
//if (toParent() == cd->toParent())
if (cd && getModule() == cd->getModule())
if (cd && getAccessModule() == cd->getAccessModule())
{
#if LOG
printf("\tin same module\n");
Expand Down Expand Up @@ -354,7 +354,7 @@ int AggregateDeclaration::hasPrivateAccess(Dsymbol *smember)
#endif
return 1;
}
if (!cd && getModule() == smember->getModule())
if (!cd && getAccessModule() == smember->getAccessModule())
{
#if LOG
printf("\tyes 3\n");
Expand All @@ -381,38 +381,32 @@ void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d)
}
else
{
//printf("accessCheck(%s)\n", d->toChars());
printf("accessCheck(%s)\n", d->toPrettyChars());
}
#endif
if (!e)
{
if (d->prot() == PROTprivate && d->getModule() != sc->module ||
if (d->prot() == PROTprivate && d->getAccessModule() != sc->module ||
d->prot() == PROTpackage && !hasPackageAccess(sc, d))

error(loc, "%s %s.%s is not accessible from %s",
d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars());
{
error(loc, "%s %s is not accessible from module %s",
d->kind(), d->toPrettyChars(), sc->module->toChars());
}
}
else if (e->type->ty == Tclass)
{ // Do access check
ClassDeclaration *cd;

cd = (ClassDeclaration *)(((TypeClass *)e->type)->sym);
#if 1
ClassDeclaration *cd = (ClassDeclaration *)(((TypeClass *)e->type)->sym);
if (e->op == TOKsuper)
{ ClassDeclaration *cd2;

cd2 = sc->func->toParent()->isClassDeclaration();
{
ClassDeclaration *cd2 = sc->func->toParent()->isClassDeclaration();
if (cd2)
cd = cd2;
}
#endif
cd->accessCheck(loc, sc, d);
}
else if (e->type->ty == Tstruct)
{ // Do access check
StructDeclaration *cd;

cd = (StructDeclaration *)(((TypeStruct *)e->type)->sym);
StructDeclaration *cd = (StructDeclaration *)(((TypeStruct *)e->type)->sym);
cd->accessCheck(loc, sc, d);
}
}
39 changes: 33 additions & 6 deletions src/dsymbol.c
Expand Up @@ -641,26 +641,53 @@ void Dsymbol::checkDeprecated(Loc loc, Scope *sc)

Module *Dsymbol::getModule()
{
Module *m;
Dsymbol *s;

//printf("Dsymbol::getModule()\n");
TemplateDeclaration *td = getFuncTemplateDecl(this);
if (td)
return td->getModule();

s = this;
Dsymbol *s = this;
while (s)
{
//printf("\ts = '%s'\n", s->toChars());
m = s->isModule();
//printf("\ts = %s '%s'\n", s->kind(), s->toPrettyChars());
Module *m = s->isModule();
if (m)
return m;
s = s->parent;
}
return NULL;
}

/**********************************
* Determine which Module a Dsymbol is in, as far as access rights go.
*/

Module *Dsymbol::getAccessModule()
{
//printf("Dsymbol::getAccessModule()\n");
TemplateDeclaration *td = getFuncTemplateDecl(this);
if (td)
return td->getAccessModule();

Dsymbol *s = this;
while (s)
{
//printf("\ts = %s '%s'\n", s->kind(), s->toPrettyChars());
Module *m = s->isModule();
if (m)
return m;
TemplateInstance *ti = s->isTemplateInstance();
if (ti && ti->isnested)
/* Because of local template instantiation, the parent isn't where the access
* rights come from - it's the template declaration
*/
s = ti->tempdecl;
else
s = s->parent;
}
return NULL;
}

/*************************************
*/

Expand Down
1 change: 1 addition & 0 deletions src/dsymbol.h
Expand Up @@ -131,6 +131,7 @@ struct Dsymbol : Object
void verror(Loc loc, const char *format, va_list ap);
void checkDeprecated(Loc loc, Scope *sc);
Module *getModule();
Module *getAccessModule();
Dsymbol *pastMixin();
Dsymbol *toParent();
Dsymbol *toParent2();
Expand Down

0 comments on commit c504c3f

Please sign in to comment.