Bug 3510 – Cannot forward reference a templated type from within a template mixin

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2009-11-14T12:30:00Z
Last change time
2014-04-18T09:12:06Z
Keywords
rejects-valid
Assigned to
nobody
Creator
matti.niemenmaa+dbugzilla
Blocks
340

Comments

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
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/2c3e9a8b007d62493c52ca601173ff2cd9cd9c0a fix Issue 3510 - Cannot forward reference a templated type from within a template mixin
Comment #2 by github-bugzilla — 2012-03-12T20:02:40Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1ac0b1021b77190f512399a2bde9bfac7e05f940 fix Issue 3510 - Cannot forward reference a templated type from within a template mixin