for a mixin it is important where the template is declared.
mixin T!(int);
template T(t){
t a;
}
does not work. Error: mixin forward reference to template.
In one module this is no problem. I can modify the sequence.
The problem comes, if the template and the mixin are in different modules.
I added "import A" to my file "B", and _suddenly_ the compile fails in module "C" with the "forward refer..." message.
In module "C" i also have an "import A" and there I use mixins with
templates out of A.
I changed the source file order in the dmd command line and it compiles. So it seems to me, it is the sequence of template declaration and mixin which depends on the order of the source files.
Solution should be to drop the dependency to the sequence template declaration and mixin.
My project relies very strong on the mixin feature. :(
Please give this bug a high priority.
Comment #1 by thomas-dloop — 2006-04-18T01:35:27Z
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[email protected] schrieb am 2006-04-14:
> for a mixin it is important where the template is declared.
>
> mixin T!(int);
> template T(t){
> t a;
> }
>
> does not work. Error: mixin forward reference to template.
>
> In one module this is no problem. I can modify the sequence.
> The problem comes, if the template and the mixin are in different modules.
>
> I added "import A" to my file "B", and _suddenly_ the compile fails in module
> "C" with the "forward refer..." message.
> In module "C" i also have an "import A" and there I use mixins with
> templates out of A.
>
> I changed the source file order in the dmd command line and it compiles. So it
> seems to me, it is the sequence of template declaration and mixin which depends
> on the order of the source files.
>
> Solution should be to drop the dependency to the sequence template declaration
> and mixin.
Added to DStress as
http://dstress.kuehne.cn/compile/f/forward_reference_13_E.d
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFERJGB3w+/yD4P9tIRAvQLAKCZlMeVCuB2WGV975S0pfioob051ACfTKWi
3gBu7yGjWtVeFKhflqz73GQ=
=LV2Z
-----END PGP SIGNATURE-----
Comment #2 by benoit — 2006-04-18T13:14:52Z
The workaround "changing the source file order" does not always help.
I changed the file order manually and dmd fails also.
In the moment I cannot compile code, that is compilable in another file constellation.
my actual situation: FileA uses mixins from FileB. I put FileB as the first file in the source file list, FileA as last.
-v output is:
it passes all files with "parse". Than the first file with "semantic" is FileB, but it failes here with:
..FileA(..): mixin forward reference to template
I repeat, FileA+FileB do compile if they are part of another build process.
So I think this should be marked as "blocker".
Comment #3 by bugzilla — 2006-06-20T02:16:56Z
Fixed 0.161
Comment #4 by braddr — 2006-07-23T17:05:17Z
Created attachment 18
Bug from Anders
Comment #5 by braddr — 2006-07-23T17:06:12Z
Created attachment 19
Bug from Anders
Comment #6 by benoit — 2006-07-23T17:37:12Z
In the chat, Anders had a problem with forward references.
I believe this code should work. Is this error really solved?
I attached the sources.
Comment #7 by bugzilla — 2006-07-26T20:59:30Z
The attachments are type 'tgz'. I don't know what they are. Please use plaintext files where ever possible.
Comment #8 by smjg — 2006-07-27T05:59:21Z
.tgz is short for .tar.gz, i.e. an archive of files that has been tarred and then gzipped. Such things tend to originate on Unix-type systems. Many file compression programs, including WinZip, can open these.
Comment #9 by davidl — 2007-01-22T23:50:10Z
the bug is fixed in 1.0. i don't know if that's a good news or a bad one. maybe it would hide something? would it fail at more complicated cases?
Comment #10 by braddr — 2007-01-23T00:58:19Z
Taking a closer look at the attachment, compiling dbug/bug/queue.d via 'dmd -c queue.d' produced an error:
$ dmd -c queue.d
queue.d(9): class queue.MessageQueue is forward referenced when looking for 'ListHead'
queue.d(9): class queue.MessageQueue is forward referenced when looking for 'ListHead'
arm.d(12): Error: no property 'ListHead' for type 'queue.MessageQueue'
arm.d(12): Error: MessageQueue.ListHead is used as a type
arm.d(12): variable arm.Arm.mqueue voids have no value
Compiling the entire set together: dmd main.d list.d queue.d arm.d (or in any other order that I tried) succeeds. This indicates to me that the bug is NOT fixed. The code is certainly more verbose than it needs to be to be a minimal test case, but it _does_ show that there's an error still. Re-opening the issue.
Comment #11 by davidl — 2007-02-12T19:57:05Z
yep , i tested it on 1.005. it still fails. umm dmd -c queue.d would have the forward reference problem.
Comment #12 by braddr — 2007-02-15T12:54:52Z
reverting david's version change. Please stop that.
Comment #13 by bugzilla — 2009-07-02T02:21:27Z
A simpler example:
=== test.d ===
import list, arm;
class Queue {
mixin List;
Arm a;
}
class MessageQueue : Queue { }
=== arm.d ===
import list, test;
class Arm {
mixin List;
MessageQueue.ListHead mqueue;
}
=== list.d ===
template List() {
struct ListHead { }
}
===================
compile with:
dmd test
gives:
test.d(8): Error: class test.MessageQueue is forward referenced when looking for 'ListHead'
Comment #14 by bugzilla — 2009-07-02T02:28:20Z
Even simpler:
=== test.d ===
import test;
class Arm {
typedef int ListHead;
MessageQueue.ListHead mqueue;
}
=== arm.d ===
import arm;
class Queue {
typedef int ListHead;
Arm a;
}
class MessageQueue : Queue {
}
=============