Comment #0 by matti.niemenmaa+dbugzilla — 2009-11-14T12:30:29Z
Simple case:
struct S(int x) {}
template Mix() { Sa s; }
class C {
mixin Mix!();
alias S!(0) Sa;
}
foo.d(2): Error: forward reference to 'S!(0)'
foo.d(2): Error: Sa is used as a type
foo.d(2): Error: variable foo.C.Mix!().s voids have no value
foo.d(5): Error: mixin foo.C.Mix!() error instantiating
Move the mixin of Mix!() below the alias of S!() and it compiles.
For the following code, that move alone isn't enough:
template Tuple(T...) { alias T Tuple; }
struct S(size_t x) {}
template Mix() { Sa s; }
class C {
mixin Mix!();
alias Tuple!("foo") T;
alias S!(T.length) Sa;
}
[same errors as above]
Moving the mixin below the alias of S!() gives:
foo.d(8): Error: identifier 'length' of 'T.length' is not defined
foo.d(8): Error: template instance S!(int) does not match template declaration S(uint x)
foo.d(4): Error: template instance S!(int) is used as a type
foo.d(4): Error: variable foo.C.Mix!().s voids have no value
foo.d(9): Error: mixin foo.C.Mix!() error instantiating
After moving the mixin, the code can still be made to compile by introducing a constant to hold the length. The following class C works:
alias Tuple!("foo") T;
const size_t Tlength = T.length;
alias S!(Tlength) Sa;
mixin Mix!();
Unfortunately, in my case T depends on Mix in ways the compiler can't figure out without having Mix mixed in before T (Bug 3509), so this is a blocker for me.
Comment #1 by github-bugzilla — 2012-03-12T20:02:19Z