Skip to content

Commit

Permalink
Fix 'enclosing' symbol propagation in TemplateInstance::hasNestedArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Sep 9, 2015
1 parent d96a649 commit e7898a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -7167,6 +7167,12 @@ bool TemplateInstance::hasNestedArgs(Objects *args, bool isstatic)
int nested = 0;
//printf("TemplateInstance::hasNestedArgs('%s')\n", tempdecl->ident->toChars());

if (!enclosing)
{
if (TemplateInstance *ti = tempdecl->isInstantiated())
enclosing = ti->enclosing;
}

/* A nested instance happens when an argument references a local
* symbol that is on the stack.
*/
Expand Down Expand Up @@ -7294,6 +7300,10 @@ Dsymbols *TemplateInstance::appendToModuleMember()
mi = NULL;
}

//printf("%s->appendToModuleMember() enclosing = %s mi = %s\n",
// toPrettyChars(),
// enclosing ? enclosing->toPrettyChars() : NULL,
// mi ? mi->toPrettyChars() : NULL);
if (!mi || mi->isRoot())
{
/* If the instantiated module is speculative or root, insert to the
Expand All @@ -7304,7 +7314,7 @@ Dsymbols *TemplateInstance::appendToModuleMember()

// insert target is made stable by using the module
// where tempdecl is declared.
mi = tempdecl->getModule();
mi = (enclosing ? enclosing : tempdecl)->getModule();
if (!mi->isRoot())
mi = mi->importedFrom;
assert(mi->isRoot());
Expand All @@ -7317,6 +7327,7 @@ Dsymbols *TemplateInstance::appendToModuleMember()
* - codegen pass won't reach to the instance.
*/
}
//printf("\t--> mi = %s\n", mi->toPrettyChars());

Dsymbols *a = mi->members;
for (size_t i = 0; 1; i++)
Expand Down
21 changes: 21 additions & 0 deletions test/runnable/ice15030.d
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,25 @@ function b.__unittestL5_2.__lambda1.__lambda2.__lambda2
By using `deferredNested` correctly, those nested function generations are ordered again.
Fixed more:
--------
function D main
code a
code b
function b.__unittestL5_2
function b.__unittestL5_2.__lambda1
function b.__unittestL5_2.__lambda1.__lambda2
function b.__unittestL5_2.__lambda1.__lambda2.filter!(int[]).filter
function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.this
function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.empty
function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.front
function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.popFront
function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xopEquals
function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xtoHash
function b.__unittestL5_2.__lambda1.__lambda2.__lambda2
Another problem is in TemplateInstance::hasNestedArgs. By inheriting 'enclosing' of instantiated scope,
now 'filter!(int[])' also becomes a nested template, and then FilterResult!(...) goes into the module b.
+/

0 comments on commit e7898a6

Please sign in to comment.