www.digitalmars.com         C & C++   DMDScript  

D - BUG?: Private imports -> Forward references

reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
Hi!

I have mentioned this problem before, and after some
looking and the creation of a minimal example, I feel
that I have created a good case.

Doing
dmd -c bar.d
produce
foo2.d: class foo2 forward reference of base class bar

Doing
dmd -c bar.d foo1.d foo2.d
yields the same

Doing
dmd -c foo1.d foo2.d bar.d
works without a hitch.

According to the D lang spec
quote:
"
If the import is private, such as:

module abc;
private import def;

then def is not searched when another module imports abc.
"

In my example, foo2 is clearly searched, even though it's
a private import in the imported module. If such circular
forward references really is a problem, then private imports
must be the way to fix them. Personally, I believe that this
is a bug since it only pops up when foo2 (as a subclass) is
imported (indirectly and wrongly in this case) into the module
where the base class is defined.

--------------

module bar;

private import foo1;

class bar {

}

--------------

module foo1;

private import foo2;

class foo1 {

}

---------------

module foo2;

private import bar;

class foo2 : bar {

}

---------------

Lars Ivar Igesund
Sep 30 2003
parent reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
It would be really nice if this bug could be either verified or
falsified. Such forward reference messages are real pain in
the a** as it means that the project must be compiled all at
once (not one and one file using -c). And when all files are
used as input at once, the error messages are way too unclear
because they assumes that you use only one input file and thus
the offending file name isn't printed (which is no good when there
are 20+ source files.).

Lars Ivar Igesund

"Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
news:blbji1$2un5$1 digitaldaemon.com...
 Hi!

 I have mentioned this problem before, and after some
 looking and the creation of a minimal example, I feel
 that I have created a good case.

 Doing
 dmd -c bar.d
 produce
 foo2.d: class foo2 forward reference of base class bar

 Doing
 dmd -c bar.d foo1.d foo2.d
 yields the same

 Doing
 dmd -c foo1.d foo2.d bar.d
 works without a hitch.

 According to the D lang spec
 quote:
 "
 If the import is private, such as:

 module abc;
 private import def;

 then def is not searched when another module imports abc.
 "

 In my example, foo2 is clearly searched, even though it's
 a private import in the imported module. If such circular
 forward references really is a problem, then private imports
 must be the way to fix them. Personally, I believe that this
 is a bug since it only pops up when foo2 (as a subclass) is
 imported (indirectly and wrongly in this case) into the module
 where the base class is defined.

 --------------

 module bar;

 private import foo1;

 class bar {

 }

 --------------

 module foo1;

 private import foo2;

 class foo1 {

 }

 ---------------

 module foo2;

 private import bar;

 class foo2 : bar {

 }

 ---------------

 Lars Ivar Igesund

Nov 13 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
news:bovno1$316c$1 digitaldaemon.com...
 It would be really nice if this bug could be either verified or
 falsified. Such forward reference messages are real pain in
 the a** as it means that the project must be compiled all at
 once (not one and one file using -c). And when all files are
 used as input at once, the error messages are way too unclear
 because they assumes that you use only one input file and thus
 the offending file name isn't printed (which is no good when there
 are 20+ source files.).

I agree it's a problem. I'm not sure what to do about it, but I'll keep it in the bug list until it is properly resolved.
Jan 05 2004
parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I am also starting to see this problem in my code.  IMHO, one of the 
great selling points of D is that you can import other modules 
whilly-nilly without having to worry about forward references and other 
C header nightmares.  This bug undercuts that feature.

Walter, I know you know about this bug.  I'm just hoping I can push this 
to the top of the heap :)

Russ

Walter wrote:
 "Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
 news:bovno1$316c$1 digitaldaemon.com...
 
It would be really nice if this bug could be either verified or
falsified. Such forward reference messages are real pain in
the a** as it means that the project must be compiled all at
once (not one and one file using -c). And when all files are
used as input at once, the error messages are way too unclear
because they assumes that you use only one input file and thus
the offending file name isn't printed (which is no good when there
are 20+ source files.).

I agree it's a problem. I'm not sure what to do about it, but I'll keep it in the bug list until it is properly resolved.

Feb 27 2004