[Issue 1392] New: Templates w/ forwd refs fail when in separate modules.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 31 13:26:59 PDT 2007


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

           Summary: Templates w/ forwd refs fail when in separate modules.
           Product: D
           Version: 1.015
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: cdunn2001 at gmail.com


fooA.d
------
import fooFoo;
class A{
  static int hi(){
    //auto x = new F;
    //F.there();
    return 0;
  }
  //Foo!(char) x;
};
Foo!(char)* x;
---
fooFoo.d
--------
import fooA;
class Foo(T){
  //A* bar(){
  //  return null; //return A.hi();
  //}
  int i;
};
---
I've commented out anything which could confuse the issue.  The problem is
strictly the circular 'import' of the module which defines the template and the
module which specializes it, independent of whether Foo and A actually depend
on each other.

If these are in the same module, it compiles, even with all the extra stuff,
and even with refs instead of pointers.

combined.d
----------
alias Foo!(char) F;
class A{
  static int hi(){
    auto x = new F;
    F.there();
    return 0;
  }
  F x;
};
class Foo(T){
  A bar(){
    A.hi();
    return new A;
  }
  int i;
};
---

In fact, it works if I compile them at the same time, with:
  dmd -c fooA.d fooFoo.d
Interestingly, this produces two object files, fooA.o and fooFoo.o, which can
then be linked into an executable.  So the problem comes from compiling just
fooFoo.d into fooFoo.o:
  dmd -c fooFoo.d
  fooA.d(11): template instance forward reference to template declaration
Foo(T)
  fooA.d(11): Error: Foo!(char) is used as a type

In other words, this is not a bug in the language, but rather a bug in
compilation.  Since I can work around it by just compiling all modules in a
package simultaneously, it is not a critical issue, but if it is not fixed, I
think people will run into this problem repeatedly.  It might make compilation
slower too, since in practice, any change will force recompilation of all
modules.

Please let me know if you need more details.

(This is perhaps related to Bug 805 and #877.)


-- 



More information about the Digitalmars-d-bugs mailing list