Skip to content

Commit

Permalink
Merge pull request #4469 from 9rnsr/fix12152
Browse files Browse the repository at this point in the history
Issue 12152 - Cannot forward reference subclass member in superclass
  • Loading branch information
WalterBright committed Mar 27, 2015
2 parents 3605942 + 91dd1ff commit a17015a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/class.c
Expand Up @@ -548,15 +548,30 @@ void ClassDeclaration::semantic(Scope *sc)
}
}
Lancestorsdone:
//printf("\tClassDeclaration::semantic(%s) doAncestorsSemantic = %d\n", toChars(), doAncestorsSemantic);

if (!members) // if opaque declaration
{
semanticRun = PASSsemanticdone;
return;
}
if (!symtab)
{
symtab = new DsymbolTable();

/* Bugzilla 12152: The semantic analysis of base classes should be finished
* before the members semantic analysis of this class, in order to determine
* vtbl in this class. However if a base class refers the member of this class,
* it can be resolved as a normal forward reference.
* Call addMember() to make this class members visible from the base classes.
*/
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->addMember(sc, this, 1);
}
}

for (size_t i = 0; i < baseclasses->dim; i++)
{
BaseClass *b = (*baseclasses)[i];
Expand Down Expand Up @@ -597,12 +612,6 @@ void ClassDeclaration::semantic(Scope *sc)
}
interfaceSemantic(sc);

for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->addMember(sc, this, 1);
}

/* If this is a nested class, add the hidden 'this'
* member which is a pointer to the enclosing scope.
*/
Expand Down
16 changes: 16 additions & 0 deletions test/compilable/testfwdref.d
@@ -0,0 +1,16 @@
// PERMUTE_ARGS:

/***************************************************/
// 12152

class A12152
{
alias Y = B12152.X;
}

class B12152 : A12152
{
alias int X;
}

static assert(is(A12152.Y == int));

0 comments on commit a17015a

Please sign in to comment.