Skip to content

Commit

Permalink
Merge pull request #5516 from 9rnsr/fix15733
Browse files Browse the repository at this point in the history
[REG2.066] Issue 15733 - Forward reference issue involving inheritance
  • Loading branch information
WalterBright committed Mar 19, 2016
2 parents cd8e317 + f6426fe commit 5264c96
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 19 deletions.
77 changes: 58 additions & 19 deletions src/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,42 @@ public:

if (baseok < BASEOKdone)
{
/* Bugzilla 12078, 12143 and 15733:
* While resolving base classes and interfaces, a base may refer
* the member of this derived class. In that time, if all bases of
* this class can be determined, we can go forward the semantc process
* beyond the Lancestorsdone. To do the recursive semantic analysis,
* temporarily set and unset `_scope` around exp().
*/
T resolveBase(T)(lazy T exp)
{
if (!scx)
{
scx = sc.copy();
scx.setNoFree();
}
static if (!is(T == void))
{
_scope = scx;
auto r = exp();
_scope = null;
return r;
}
else
{
_scope = scx;
exp();
_scope = null;
}
}

baseok = BASEOKin;

// Expand any tuples in baseclasses[]
for (size_t i = 0; i < baseclasses.dim;)
{
_scope = scx ? scx : sc.copy();
_scope.setNoFree();

BaseClass* b = (*baseclasses)[i];
//printf("+ %s [%d] b->type = %s\n", toChars(), i, b->type->toChars());
b.type = b.type.semantic(loc, sc);
//printf("- %s [%d] b->type = %s\n", toChars(), i, b->type->toChars());

_scope = null;
auto b = (*baseclasses)[i];
b.type = resolveBase(b.type.semantic(loc, sc));

Type tb = b.type.toBasetype();
if (tb.ty == Ttuple)
Expand Down Expand Up @@ -555,7 +577,7 @@ public:
b.sym = baseClass;

if (tc.sym._scope && tc.sym.baseok < BASEOKdone)
tc.sym.semantic(null); // Try to resolve forward reference
resolveBase(tc.sym.semantic(null)); // Try to resolve forward reference
if (tc.sym.baseok < BASEOKdone)
{
//printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars());
Expand Down Expand Up @@ -605,7 +627,7 @@ public:
b.sym = tc.sym;

if (tc.sym._scope && tc.sym.baseok < BASEOKdone)
tc.sym.semantic(null); // Try to resolve forward reference
resolveBase(tc.sym.semantic(null)); // Try to resolve forward reference
if (tc.sym.baseok < BASEOKdone)
{
//printf("\ttry later, forward reference of base %s\n", tc->sym->toChars());
Expand Down Expand Up @@ -1511,18 +1533,35 @@ public:

if (baseok < BASEOKdone)
{
T resolveBase(T)(lazy T exp)
{
if (!scx)
{
scx = sc.copy();
scx.setNoFree();
}
static if (!is(T == void))
{
_scope = scx;
auto r = exp();
_scope = null;
return r;
}
else
{
_scope = scx;
exp();
_scope = null;
}
}

baseok = BASEOKin;

// Expand any tuples in baseclasses[]
for (size_t i = 0; i < baseclasses.dim;)
{
_scope = scx ? scx : sc.copy();
_scope.setNoFree();

BaseClass* b = (*baseclasses)[i];
b.type = b.type.semantic(loc, sc);

_scope = null;
auto b = (*baseclasses)[i];
b.type = resolveBase(b.type.semantic(loc, sc));

Type tb = b.type.toBasetype();
if (tb.ty == Ttuple)
Expand Down Expand Up @@ -1599,7 +1638,7 @@ public:
b.sym = tc.sym;

if (tc.sym._scope && tc.sym.baseok < BASEOKdone)
tc.sym.semantic(null); // Try to resolve forward reference
resolveBase(tc.sym.semantic(null)); // Try to resolve forward reference
if (tc.sym.baseok < BASEOKdone)
{
//printf("\ttry later, forward reference of base %s\n", tc->sym->toChars());
Expand Down
13 changes: 13 additions & 0 deletions test/runnable/testclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ class Concrete13353 : Derived13353
void func() {}
}

/***************************************************/
// 15733

class CStmt15733 : CNode15733 {}
class CDecl15733 : CStmt15733 {}
class CNode15733 { mixin CMix!CDecl15733; }
template CMix(T){ mixin("static " ~ T.stringof ~ " x;"); }

interface IStmt15733 : INode15733 {}
interface IDecl15733 : IStmt15733 {}
interface INode15733 { mixin IMix!IDecl15733; }
template IMix(T){ mixin("static " ~ T.stringof ~ " x;"); }

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

int main()
Expand Down

0 comments on commit 5264c96

Please sign in to comment.