[Issue 10877] New: Possible regression: Cannot access frame of function in opCall

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 23 16:18:51 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10877

           Summary: Possible regression: Cannot access frame of function
                    in opCall
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-08-23 16:18:50 PDT ---
I've had this test-case in my minilib library for quite some time. It used to
work in git-head versions, but not anymore, and it seems I can't get any
release versions to run it (it's possible I ever tested it with git-head
versions). Some git-head commits must have worked at some point but the
following is now failing:

-----
module test;

import std.typetuple;

/**
    Associate default values to a function in reverse.
*/
template CurryDefVal(alias Call, DefVals...)
{
    // can't add constraints due to compiler bugs

    static if (is(typeof( CurryDefValImpl1!(Call, DefVals) )))
    {
        alias CurryDefValImpl1!(Call, DefVals) CurryDefVal;
    }
    else  // can't add check due to compiler bugs
    {
        alias CurryDefValImpl2!(Call, DefVals) CurryDefVal;
    }
}

///
void test()
{
    static void foo(int x, float y, string z)
    {
    }

    alias CurryDefVal!(foo, "a", 1.0, 1) fooDef3;
    alias CurryDefVal!(foo, "a", 1.0) fooDef2;
    alias CurryDefVal!(foo, "a") fooDef1;
    alias CurryDefVal!(foo) fooDef0;
    alias CurryDefVal!(fooDef1, 2.0, 3) fooDef3_clone;

    fooDef0(1, 1.0, "a");
    fooDef1(1, 1.0);
    fooDef2(1);
    fooDef3();
    fooDef3_clone();

    // demonstrates alias of scoped function
    static void testMe(ref int y)
    {
        if (y == 10)
            return;

        // failing all, used to work
        alias CurryDefVal!(testMe, y) recurse;

        y = 10;
        recurse();
    }

    int x;
    testMe(x);
}

/* helper */
template CurryDefValImpl1(alias Call, DefVals...)
    if (isCallable!Call && DefVals.length <= ParameterTypeTuple!Call.length)
{
    auto CurryDefValImpl1(T...)(T args)
    {
        return Call(args, Reverse!DefVals);
    }
}

/* helper */
struct CurryDefValImpl2(alias Call, DefVals...)
{
    static auto opCall(T...)(T args)
    {
        return Call(args, Reverse!DefVals);
    }
}

void main()
{
}
-----

Errors:

test.d(49): Error: function test.test.testMe.CurryDefValImpl2!(testMe,
y).CurryDefValImpl2.opCall!().opCall cannot access frame of function
test.test.testMe

test.d(74): Error: function test.test.testMe.CurryDefValImpl2!(testMe,
y).CurryDefValImpl2.opCall!().opCall cannot access frame of function
test.test.testMe

test.d(52): Error: template instance test.test.testMe.CurryDefValImpl2!(testMe,
y).CurryDefValImpl2.opCall!() error instantiating

I've first introduced this as a similar function in Issue 5829. Once this frame
access issue is resolved (if it can be - bit it used to work), we could
introduce it into Phobos if it's useful to have after cleaning it up. And yes,
the name should be "partial function application" or something like that rather
than curry.

-- 
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