From 99396c2e7a72eb27f0a1d56d27cd354f184cc3d7 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Tue, 9 Dec 2008 14:57:01 +0100 Subject: [PATCH] Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 . --- gen/functions.cpp | 35 +++++++++++++++++++++-------------- tests/mini/compile_nested2.d | 13 +++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 tests/mini/compile_nested2.d diff --git a/gen/functions.cpp b/gen/functions.cpp index 9e9065b3..94270323 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -771,24 +771,31 @@ void DtoDefineFunc(FuncDeclaration* fd) if (!fd->nestedVars.empty()) { 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; - Dsymbol* par = fd->toParent2(); - while (par) + if (!fd->isStatic()) { - 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; diff --git a/tests/mini/compile_nested2.d b/tests/mini/compile_nested2.d new file mode 100644 index 00000000..e05a4ffc --- /dev/null +++ b/tests/mini/compile_nested2.d @@ -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(); + } +}