www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9990] New: templates with function alias cause forward reference error

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9990

           Summary: templates with function alias cause forward reference
                    error
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: SebastianGraf t-online.de


--- Comment #0 from Sebastian Graf <SebastianGraf t-online.de> 2013-04-25
04:43:50 PDT ---
import std.stdio;

struct S { string field; }

auto initS() { return S("hi"); }

class C(alias init)
{
    private S _s;

    this() { _s = init(); }

    auto createProxy()
    {
        struct Proxy
        {
            private S* s;
            void print() { writeln(s.field); }
        }
        return Proxy(&_s);
    }
}

// alias SC = C!(initS);
static assert(!is(typeof(C!(initS))));

void main() 
{
    alias SC = C!(initS);
    auto c = new SC;
    c.createProxy().print();
}

This prints out "hi". If I alias SC at the global level instead, I get a
compiler error:
hi.d(24): Error: template instance hi.C!(initS) forward reference of function
initS

Line 24 is the line with the offending global alias. I think the global version
should also compile.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 25 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9990


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-04-25 07:14:54 PDT ---
Reduced test case:

auto initS() { return "hi"; }
class C(alias init) {}
alias SC = C!(initS);

Compiler fix:
https://github.com/D-Programming-Language/dmd/pull/1936

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 25 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9990



--- Comment #2 from github-bugzilla puremagic.com 2013-04-26 12:57:39 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7f6f1acdf25b2c968102587c9da0d1b033eea6e6
fix Issue 9990 - templates with function alias cause forward reference error

https://github.com/D-Programming-Language/dmd/commit/661ac097995a79674a07db38469e58e5cf9e530a
Merge pull request #1936 from 9rnsr/fix9990

Issue 9990 - templates with function alias cause forward reference error

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 26 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9990


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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