mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-14 15:16:07 +03:00
Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
This commit is contained in:
parent
3c400ff21c
commit
99396c2e7a
2 changed files with 34 additions and 14 deletions
|
@ -771,24 +771,31 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||||
if (!fd->nestedVars.empty())
|
if (!fd->nestedVars.empty())
|
||||||
{
|
{
|
||||||
Logger::println("has nested frame");
|
Logger::println("has nested frame");
|
||||||
// start with add all enclosing parent frames
|
// start with adding all enclosing parent frames until a static parent is reached
|
||||||
int nparelems = 0;
|
int nparelems = 0;
|
||||||
Dsymbol* par = fd->toParent2();
|
if (!fd->isStatic())
|
||||||
while (par)
|
|
||||||
{
|
{
|
||||||
if (FuncDeclaration* parfd = par->isFuncDeclaration())
|
Dsymbol* par = fd->toParent2();
|
||||||
|
while (par)
|
||||||
{
|
{
|
||||||
nparelems += parfd->nestedVars.size();
|
if (FuncDeclaration* parfd = par->isFuncDeclaration())
|
||||||
|
{
|
||||||
|
nparelems += parfd->nestedVars.size();
|
||||||
|
// stop at first static
|
||||||
|
if (parfd->isStatic())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (ClassDeclaration* parcd = par->isClassDeclaration())
|
||||||
|
{
|
||||||
|
// nothing needed
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
par = par->toParent2();
|
||||||
}
|
}
|
||||||
else if (ClassDeclaration* parcd = par->isClassDeclaration())
|
|
||||||
{
|
|
||||||
// nothing needed
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
par = par->toParent2();
|
|
||||||
}
|
}
|
||||||
int nelems = fd->nestedVars.size() + nparelems;
|
int nelems = fd->nestedVars.size() + nparelems;
|
||||||
|
|
||||||
|
|
13
tests/mini/compile_nested2.d
Normal file
13
tests/mini/compile_nested2.d
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
void test(void delegate() spam)
|
||||||
|
{
|
||||||
|
static void foo() // static is the problem
|
||||||
|
{
|
||||||
|
uint x;
|
||||||
|
void peek() { x = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
void bar()
|
||||||
|
{
|
||||||
|
spam();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue