www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6312] New: template instance cannot use argument from enclosing template

reply d-bugmail puremagic.com writes:
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



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: -------
Jul 14 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6312




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: -------
Nov 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6312


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

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



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: -------
Apr 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6312




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


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: -------
Apr 06 2013
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Apr 06 2013