Thread overview
[bug] static constructor not invoked for 'inner' class
May 03, 2004
Kris
Jun 02, 2004
Kris
Aug 29, 2004
Walter
May 03, 2004
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


June 02, 2004
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
>
>


August 29, 2004
This works correctly when I try it. -Walter