www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [bug] static constructor not invoked for 'inner' class

reply "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
D doesn't have inner classes per se, but you can happily declare a class
within a method/function/class, which is great. However, if you declare one
of these 'inner' classes with a static constructor, said constructor never
gets invoked.

I don't have the example any more, but it was along these lines:

void testSomething()
{
        class Inner
        {
              static this()
              {
              // never called
              }

              this()
              {
              // called correctly
              }
        }

        Inner inner = new Inner();
}


Moving the Inner class to module scope resolves the issue, but that's not
the point ...

- Kris
May 02 2004
parent reply "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
Here's an example of the bug:

void main()
{
        class S
        {
                static this()
                {
                printf ("static constructor\n");
                }

                this()
                {
                printf ("class constructor\n");
                }
        }

        new S;
}

- Kris

"Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message
news:c74fis$gfi$1 digitaldaemon.com...
 D doesn't have inner classes per se, but you can happily declare a class
 within a method/function/class, which is great. However, if you declare
one
 of these 'inner' classes with a static constructor, said constructor never
 gets invoked.

 I don't have the example any more, but it was along these lines:

 void testSomething()
 {
         class Inner
         {
               static this()
               {
               // never called
               }

               this()
               {
               // called correctly
               }
         }

         Inner inner = new Inner();
 }


 Moving the Inner class to module scope resolves the issue, but that's not
 the point ...

 - Kris
Jun 02 2004
parent "Walter" <newshound digitalmars.com> writes:
This works correctly when I try it. -Walter
Aug 29 2004