[Issue 2671] New: Circular imports and static constructors in templates

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 16 06:04:32 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2671

           Summary: Circular imports and static constructors in templates
           Product: D
           Version: 1.039
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: samukha at voliacable.com


Static constructor in a template belongs to the module declaring the template,
not the module where the template is instantiated (for template instances that
are not mixed-in). The following works and that's cool:

----
module a;
template Foo(int i)
{
  static this()
  {
  }
}

----
module b;
import a;
alias Foo!(1) foo;

----
module c;
import a;
alias Foo!(1) foo;

----

But if we have two separate instances, the example fails with  
'Error: circular initialization dependency with module b'

----
module b;
import a;
alias Foo!(1) foo;

----
module c;
import a;
alias Foo!(2) foo;

----

If there is another way to emulate static constructors in circularly imported
modules (not by manually calling an initialization function), please share.


-- 



More information about the Digitalmars-d-bugs mailing list