Thread overview
[Issue 6312] New: template instance cannot use argument from enclosing template
Jul 14, 2011
Trass3r
Nov 11, 2011
Trass3r
Apr 06, 2013
Kenji Hara
Apr 07, 2013
Walter Bright
July 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6312

           Summary: template instance cannot use argument from enclosing
                    template
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: mrmocool@gmx.de


--- Comment #0 from Trass3r <mrmocool@gmx.de> 2011-07-14 04:16:39 PDT ---
extern(C) void printf(const char*, ...);
void h() { printf("h()"); }

class Bla
{
    mixin wrap!h;
}

mixin template wrap(alias f)
{
    void blub(alias g = f)()
    {
        g();
    }
}

void main()
{
    Bla b = new Bla();
    b.blub();
}

$ dmd -c nonlocaltemplate.d
nonlocaltemplate.d(20): Error: template instance cannot use local 'f' as
parameter to non-global template blub(alias g = f)
nonlocaltemplate.d(20): Error: template instance forward reference of f
nonlocaltemplate.d(20): Error: template instance
nonlocaltemplate.Bla.wrap!(h).blub!(f) error instantiating


Note that imho this is different from http://d.puremagic.com/issues/show_bug.cgi?id=3051 because here the argument is not on the stack but it's a template argument (and thus a compile-time value)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 11, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6312



--- Comment #1 from Trass3r <mrmocool@gmx.de> 2011-11-11 08:24:41 PST ---
Ok, here's a real ugly workaround:

extern(C) void printf(const char*, ...);
void h() { printf("h()"); }

class Bla
{
    mixin wrap!h;
}

private enum dummy {foo}

mixin template wrap(alias f)
{
    void blub(alias h = dummy)()
    {
        static if (is (h == enum))
            alias f g;
        else
            alias h g;

        g();
    }
}

void main()
{
    Bla b = new Bla();
    b.blub();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6312


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2013-04-06 02:18:06 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1850

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6312



--- Comment #3 from github-bugzilla@puremagic.com 2013-04-06 18:47:06 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/db5e6087a2ed742bb0ce024dc5154075cd54df43 fix Issue 6312 - template instance cannot use argument from enclosing template

https://github.com/D-Programming-Language/dmd/commit/f946ede5e9b597c6e32c1e66b311460204532cd9 Merge pull request #1850 from 9rnsr/fix6312

Issue 6312 - template instance cannot use argument from enclosing template

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6312


Walter Bright <bugzilla@digitalmars.com> changed:

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


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