www.digitalmars.com         C & C++   DMDScript  

D - imports and forward referencing

reply "Billy Zelsnack" <billy_zelsnack yahoo.com> writes:
I have ported a good chunk of my current project over the last week and
half. Every couple of hours I run across the dreaded..

somerandomclass.d(9): class somerandomclass is forward referenced.

I think my past experience with various other languages is messing with my
head here. I keep thinking that I have these suckers figured out and then
run into the problem again.

Eventually after reorganizing things a little I can get it going again, but
it just seems like it should work. Could someone post a quick synopsis of
the proper way of doing imports. Especially the preferred usage of private
imports. To me it seems that imports should almost always be private unless
you want to do #include style programming.
Apr 20 2004
parent reply "Billy Zelsnack" <billy_zelsnack yahoo.com> writes:
Ok. Now I really am confused. This time around I fixed the issue by just
rearranging the files on the command line.

 I have ported a good chunk of my current project over the last week and
 half. Every couple of hours I run across the dreaded..

 somerandomclass.d(9): class somerandomclass is forward referenced.
Apr 20 2004
next sibling parent Ant <duitoolkit yahoo.ca> writes:
On Wed, 21 Apr 2004 00:28:24 -0500, Billy Zelsnack wrote:

 Ok. Now I really am confused. This time around I fixed the issue by just
 rearranging the files on the command line.
 
 I have ported a good chunk of my current project over the last week and
 half. Every couple of hours I run across the dreaded..

 somerandomclass.d(9): class somerandomclass is forward referenced.
That use to be tipical on previous releases of dmd. I thought the dmd 0.82 was better on that. moving the import into the classes bodies is the easy way to fix it. Ant
Apr 20 2004
prev sibling parent reply John Reimer <jjreimer telus.net> writes:
Billy Zelsnack wrote:

 Ok. Now I really am confused. This time around I fixed the issue by just
 rearranging the files on the command line.
 
 
I have ported a good chunk of my current project over the last week and
half. Every couple of hours I run across the dreaded..

somerandomclass.d(9): class somerandomclass is forward referenced.
Yes, rearranging files has historically fixed some forward referencing issues (but not all). It's probably one of the most frustrating issues in trying to port Java source code to d, I can tell you. You may like to reduce some examples of the forward references into a simple form so that Walter can see it. DMD 0.82 apparently fixed a bunch of these issues. For some reason, if your class inherits by containment of another class, moving the import inside the class definition supposedly fixes the forward reference issues (as Ant indicated). This topic has been discussed on the newsgroup a few times before.
Apr 20 2004
parent reply =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
John Reimer wrote:

 For some reason, if your class inherits by containment of another class, 
  moving the import inside the class definition supposedly fixes the 
 forward reference issues (as Ant indicated).
Interesting... Can you post an example. I haven't been able to find any post related to this issue. Thanks ----- Julio César Carrascal Urquijo
Apr 21 2004
parent John Reimer <brk_6502 NOSP_AM.yahoo.com> writes:
Julio César Carrascal Urquijo wrote:
 John Reimer wrote:
 
 For some reason, if your class inherits by containment of another 
 class,  moving the import inside the class definition supposedly fixes 
 the forward reference issues (as Ant indicated).
Interesting... Can you post an example. I haven't been able to find any post related to this issue. Thanks ----- Julio César Carrascal Urquijo
This technique is not documented so far as I know... I believe Ant discovered it late last year and it apears to have fixed forward referencing issues in his DUI library. I'll refer you to a couple of Ant's threads: http://www.digitalmars.com/drn-bin/wwwnews?D/20837 And Andy Friesen's: http://www.digitalmars.com/drn-bin/wwwnews?D/22093 Others have run into forward referencing issues time and again (including me). DMD 0.82 reportedly fixed a few of these problems. But what bothers me about the "internal" import solution is that it is not formally recognized. It's just one of those things that seems to fix the problem. If it doesn't get documented as a standard approach, those that adopt this technique may be doomed to broken code due to future changes in the compiler. For the DWT project, though, this may be the only method to get around some major issues. SWT has a real problem with classes referencing each other inside and out. Later, John
Apr 21 2004