changeset 838:94ba810ea2b0

Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 09 Dec 2008 14:57:01 +0100
parents 331a176c1f4f
children 162a0502a6b9
files gen/functions.cpp tests/mini/compile_nested2.d
diffstat 2 files changed, 34 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/gen/functions.cpp	Tue Dec 09 14:07:30 2008 +0100
+++ b/gen/functions.cpp	Tue Dec 09 14:57:01 2008 +0100
@@ -771,24 +771,31 @@
     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;
         
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mini/compile_nested2.d	Tue Dec 09 14:57:01 2008 +0100
@@ -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();
+    }
+}