Thread overview
[Issue 3510] New: Cannot forward reference a templated type from within a template mixin
Nov 14, 2009
Matti Niemenmaa
Mar 13, 2012
Walter Bright
November 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3510

           Summary: Cannot forward reference a templated type from within
                    a template mixin
           Product: D
           Version: 1.051
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: matti.niemenmaa+dbugzilla@iki.fi
            Blocks: 340


--- Comment #0 from Matti Niemenmaa <matti.niemenmaa+dbugzilla@iki.fi> 2009-11-14 12:30:29 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3510



--- Comment #1 from github-bugzilla@puremagic.com 2012-03-12 20:02:19 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3510



--- Comment #2 from github-bugzilla@puremagic.com 2012-03-12 20:02:40 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3510


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------