Skip to content

Commit

Permalink
Merge pull request #6214 from MartinNowak/fix16607
Browse files Browse the repository at this point in the history
fix Issue 16607 - forward reference error for nested struct
  • Loading branch information
WalterBright committed Oct 27, 2016
2 parents 8e8541a + b295ff5 commit 9dfa50e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/aggregate.d
Expand Up @@ -126,6 +126,16 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
return sc2;
}

override final void setScope(Scope* sc)
{
// Might need a scope to resolve forward references. The check for
// semanticRun prevents unnecessary setting of _scope during deferred
// setScope phases for aggregates which already finished semantic().
// Also see https://issues.dlang.org/show_bug.cgi?id=16607
if (semanticRun < PASSsemanticdone)
ScopeDsymbol.setScope(sc);
}

override final void semantic2(Scope* sc)
{
//printf("AggregateDeclaration::semantic2(%s) type = %s, errors = %d\n", toChars(), type.toChars(), errors);
Expand Down
15 changes: 15 additions & 0 deletions test/compilable/test16607.d
@@ -0,0 +1,15 @@
struct A(T)
{
T t; // causes A to be SIZEOKfwd b/c B (passed as T) isn't yet done

// On the 2nd semantic pass through A, _scope of C got set again,
// even though the struct was already done.
struct C
{
}
}

struct B
{
A!B* a; // causes instantiation of A!B, but can finish semantic with A!B still being fwdref
}

0 comments on commit 9dfa50e

Please sign in to comment.