Skip to content

Commit

Permalink
Merge pull request #590 from 9rnsr/fix4675
Browse files Browse the repository at this point in the history
Issue 4675 - [tdpl] Eponymous Template should hide internal names
  • Loading branch information
WalterBright committed Jan 15, 2012
2 parents 0736834 + 6953dbf commit 91facb7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
7 changes: 6 additions & 1 deletion src/dsymbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int Dsymbol::oneMember(Dsymbol **ps)
* Same as Dsymbol::oneMember(), but look at an array of Dsymbols.
*/

int Dsymbol::oneMembers(Dsymbols *members, Dsymbol **ps)
int Dsymbol::oneMembers(Dsymbols *members, Dsymbol **ps, Identifier *ident)
{
//printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0);
Dsymbol *s = NULL;
Expand All @@ -125,6 +125,11 @@ int Dsymbol::oneMembers(Dsymbols *members, Dsymbol **ps)
}
if (*ps)
{
if (ident)
{
if (!(*ps)->ident || !(*ps)->ident->equals(ident))
continue;
}
if (s) // more than one symbol
{ *ps = NULL;
//printf("\tfalse 2\n");
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ struct Dsymbol : Object
virtual enum PROT prot();
virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
virtual int oneMember(Dsymbol **ps);
static int oneMembers(Dsymbols *members, Dsymbol **ps);
static int oneMembers(Dsymbols *members, Dsymbol **ps, Identifier *ident = NULL);
virtual int hasPointers();
virtual bool hasStaticCtorOrDtor();
virtual void addLocalClass(ClassDeclarations *) { }
Expand Down
2 changes: 2 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,8 @@ Expression *DsymbolExp::semantic(Scope *sc)
{ error("cannot make expression out of initializer for %s", v->toChars());
return new ErrorExp();
}
e = e->copy();
e->loc = loc; // for better error message
e = e->semantic(sc);
return e;
}
Expand Down
27 changes: 9 additions & 18 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,10 @@ TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id,
if (members)
{
Dsymbol *s;
if (Dsymbol::oneMembers(members, &s))
if (Dsymbol::oneMembers(members, &s, ident) && s)
{
if (s && s->ident && s->ident->equals(ident))
{
onemember = s;
s->parent = this;
}
onemember = s;
s->parent = this;
}
}
}
Expand Down Expand Up @@ -509,13 +506,10 @@ void TemplateDeclaration::semantic(Scope *sc)
if (members)
{
Dsymbol *s;
if (Dsymbol::oneMembers(members, &s))
if (Dsymbol::oneMembers(members, &s, ident) && s)
{
if (s && s->ident && s->ident->equals(ident))
{
onemember = s;
s->parent = this;
}
onemember = s;
s->parent = this;
}
}

Expand Down Expand Up @@ -4379,16 +4373,13 @@ void TemplateInstance::semantic(Scope *sc, Expressions *fargs)
if (members->dim)
{
Dsymbol *s;
if (Dsymbol::oneMembers(members, &s) && s)
if (Dsymbol::oneMembers(members, &s, tempdecl->ident) && s)
{
//printf("s->kind = '%s'\n", s->kind());
//s->print();
//printf("'%s', '%s'\n", s->ident->toChars(), tempdecl->ident->toChars());
if (s->ident && s->ident->equals(tempdecl->ident))
{
//printf("setting aliasdecl\n");
aliasdecl = new AliasDeclaration(loc, s->ident, s);
}
//printf("setting aliasdecl\n");
aliasdecl = new AliasDeclaration(loc, s->ident, s);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/win32.mak
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ aliasthis.obj : $(TOTALH) aliasthis.h aliasthis.c
apply.obj : $(TOTALH) apply.c
argtypes.obj : $(TOTALH) mtype.h argtypes.c
arrayop.obj : $(TOTALH) identifier.h declaration.h arrayop.c
attrib.obj : $(TOTALH) identifier.h declaration.h attrib.h attrib.c
attrib.obj : $(TOTALH) dsymbol.h identifier.h declaration.h attrib.h attrib.c
builtin.obj : $(TOTALH) builtin.c
canthrow.obj : $(TOTALH) canthrow.c
cast.obj : $(TOTALH) expression.h mtype.h cast.c
Expand All @@ -488,7 +488,7 @@ cond.obj : $(TOTALH) identifier.h declaration.h cond.h cond.c
declaration.obj : $(TOTALH) identifier.h attrib.h declaration.h declaration.c expression.h
delegatize.obj : $(TOTALH) delegatize.c
doc.obj : $(TOTALH) doc.h doc.c
enum.obj : $(TOTALH) identifier.h enum.h enum.c
enum.obj : $(TOTALH) dsymbol.h identifier.h enum.h enum.c
expression.obj : $(TOTALH) expression.h expression.c
func.obj : $(TOTALH) identifier.h attrib.h declaration.h func.c
hdrgen.obj : $(TOTALH) hdrgen.h hdrgen.c
Expand Down
2 changes: 1 addition & 1 deletion test/runnable/template1.d
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ void test60()
assert(thing1.sizeof == 12);
assert(thing2.sizeof == 8);

C60!(int /*,A60*/ ).C60 container1;
C60!(int /*,A60*/ ) container1;

printf("container1.sizeof: %u\n", container1.sizeof);
assert(container1.sizeof == (void*).sizeof);
Expand Down
18 changes: 18 additions & 0 deletions test/runnable/template9.d
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,24 @@ void test4413()
f.bar4(f); // ERR
}

/**********************************/
// 4675

template isNumeric(T)
{
enum bool test1 = is(T : long); // should be hidden
enum bool test2 = is(T : real); // should be hidden
enum bool isNumeric = test1 || test2;
}
void test4675()
{
static assert( isNumeric!int);
static assert(!isNumeric!string);
static assert(!__traits(compiles, isNumeric!int.test1)); // should be an error
static assert(!__traits(compiles, isNumeric!int.test2)); // should be an error
static assert(!__traits(compiles, isNumeric!int.isNumeric));
}

/**********************************/
// 5801

Expand Down

0 comments on commit 91facb7

Please sign in to comment.