[Issue 5041] New: Cannot check functor in template constraint

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 11 15:11:10 PDT 2010


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 at puremagic.com
        ReportedBy: rsinfu at gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu at gmail.com> 2010-10-11 15:10:39 PDT ---
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: -------


More information about the Digitalmars-d-bugs mailing list