www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2671] New: Circular imports and static constructors in templates

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: samukha 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.


-- 
Feb 16 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2671


Justin <mrjnewt gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrjnewt gmail.com
            Summary|Circular imports and static |Circular imports and static
                   |constructors in templates   |constructors in templates




--- Comment #1 from Justin <mrjnewt gmail.com>  2009-07-13 15:50:43 PDT ---
I can confirm this as I ran across it while working on a large project. In my
case, I use a template mixin to add a static constructor with some special
behavior to various classes sprinkled around various modules. The project
builds but gives me an error when I try running:
----------------
Error: circular initialization dependency with module epic.window
----------------

This is a pretty major hitch in my project, so I'd love to see this fixed or at
least a workaround.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 13 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2671


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |WORKSFORME


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2010-03-10
03:12:13 PST ---
I cannot reproduce this on either D1.057 or D2.041.
------ a.d -------
module a;
template Foo(int i)
{
  static this()
  {
  }
}

void main() { }
----- b.d --------
module b;
import a;
alias Foo!(1) foo;
----- c.d --------
module c;
import a;
alias Foo!(2) foo;
------------------
dmd -c a
dmd -c b
dmd -c c
dmd a.obj b.obj c.obj
a
------ this works too ----
dmd a b c
a
-----------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2010