www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5041] New: Cannot check functor in template constraint

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

           Summary: Cannot check functor in template constraint
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com



---
DMD rejects accessing to a symbol of a function object passed via template
alias parameter in template constraints.
--------------------
void main()
{
    Fun fun;
    test!fun();
}

struct Fun
{
    int opCall() { return 0; }
}

void test(alias fun)()
    if (is(int == typeof(fun())))   // (13)
{
    fun();
}
--------------------
% dmd -o- -c test.d
test.d(13): Error: function test.test(alias fun) if (is(int ==
typeof(fun()))).test cannot access frame of function D main
test.d(13): Error: function test.test(alias fun) if (is(int ==
typeof(fun()))).test cannot access frame of function D main
test.d(13): Error: function test.test(alias fun) if (is(int ==
typeof(fun()))).test cannot access frame of function D main
test.d(13): Error: function test.test(alias fun) if (is(int ==
typeof(fun()))).test cannot access frame of function D main
--------------------

Passing functor symbols via template alias parameters should be valid like
nested functions (see discussion in bug 3051), and actually, it works fine
modulo the reported problem. It's a problem of template constraints.
--------------------
void main()
{
    Fun fun;
    test!fun();
    assert(fun.value == 123);   // okay, passes
}

struct Fun
{
    int value;
    void opCall(int a) { value = a; }
}

void test(alias fun)()
{
    fun(123);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 11 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5041


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

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



Works in 2.060head.

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