[Issue 5396] Invalid code with nested functions in CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 24 21:45:15 PDT 2011


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


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #1 from Don <clugdbug at yahoo.com.au> 2011-05-24 21:40:59 PDT ---
Extended test cases (applies to delegate literals as well as inner functions):

void bug5396(int b)
{
    int inner() { return b; }
    static int staticInner() { return 6; }

    static assert(is(typeof(compiles!(
        function int () {    return 7;  }()
    ))));
    static assert(!is(typeof(compiles!(
        delegate int () {    return b;  }()
    ))));
    static assert(!is(typeof(compiles!(
        inner()
    ))));
    static assert(is(typeof(compiles!(
        staticInner()
    ))));
}

Patch in interpret.c, CallExp::interpret(). Problem is, this breaks bug 1461
which seems to be an important use case.

    if (!istate && fd && fd->isNested() && !fd->isStatic() &&
        /* BUG: Delegate literals report 'isNested()' even if they are
         * declared at module scope.
         */
        !(fd->isFuncLiteralDeclaration() &&
!fd->toParent2()->isFuncDeclaration()))
    {
        error("cannot directly interpret non-static nested function %s",
fd->toChars());
        return EXP_CANT_INTERPRET;
    }
    if (pthis && fd)
    {   // Member function call

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