Skip to content

Commit

Permalink
Merge pull request #5351 from WalterBright/fix15565
Browse files Browse the repository at this point in the history
fix Issue 15565 - Forward reference error with namespaces
  • Loading branch information
andralex committed Jan 15, 2016
2 parents 719c3bc + f42cc3b commit 7137863
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
62 changes: 44 additions & 18 deletions src/nspace.d
Expand Up @@ -41,48 +41,74 @@ public:
return ScopeDsymbol.syntaxCopy(ns);
}

override void semantic(Scope* sc)
override void addMember(Scope* sc, ScopeDsymbol sds)
{
if (semanticRun >= PASSsemantic)
return;
semanticRun = PASSsemantic;
static if (LOG)
{
printf("+Nspace::semantic('%s')\n", toChars());
}
if (_scope)
{
sc = _scope;
_scope = null;
}
parent = sc.parent;
ScopeDsymbol.addMember(sc, sds);
if (members)
{
if (!symtab)
symtab = new DsymbolTable();
// The namespace becomes 'imported' into the enclosing scope
for (Scope* sce = sc; 1; sce = sce.enclosing)
{
ScopeDsymbol sds = cast(ScopeDsymbol)sce.scopesym;
if (sds)
ScopeDsymbol sds2 = cast(ScopeDsymbol)sce.scopesym;
if (sds2)
{
sds.importScope(this, Prot(PROTpublic));
sds2.importScope(this, Prot(PROTpublic));
break;
}
}
assert(sc);
sc = sc.push(this);
sc.linkage = LINKcpp; // note that namespaces imply C++ linkage
sc.linkage = LINKcpp; // namespaces default to C++ linkage
sc.parent = this;
foreach (s; *members)
{
//printf("add %s to scope %s\n", s->toChars(), toChars());
s.addMember(sc, this);
}
sc.pop();
}
}

override void setScope(Scope* sc)
{
ScopeDsymbol.setScope(sc);
if (members)
{
assert(sc);
sc = sc.push(this);
sc.linkage = LINKcpp; // namespaces default to C++ linkage
sc.parent = this;
foreach (s; *members)
{
s.setScope(sc);
}
sc.pop();
}
}

override void semantic(Scope* sc)
{
if (semanticRun >= PASSsemantic)
return;
semanticRun = PASSsemantic;
static if (LOG)
{
printf("+Nspace::semantic('%s')\n", toChars());
}
if (_scope)
{
sc = _scope;
_scope = null;
}
parent = sc.parent;
if (members)
{
assert(sc);
sc = sc.push(this);
sc.linkage = LINKcpp; // note that namespaces imply C++ linkage
sc.parent = this;
foreach (s; *members)
{
s.importAll(sc);
Expand Down
3 changes: 3 additions & 0 deletions test/compilable/test15565.d
@@ -0,0 +1,3 @@
alias X2 = X;
extern (C++, ns) struct X {}

0 comments on commit 7137863

Please sign in to comment.