www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5396] New: Invalid code with nested functions in CTFE

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

           Summary: Invalid code with nested functions in CTFE
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: robert octarineparrot.com



18:54:57 GMT ---
The following code:
----
void outer(bool b)
{
    string inner()
    {
        if (b)
        {
            return "true";
        }
        else
        {
            return "false";
        }
    }
    pragma(msg, inner());
}
----
Compiles and evaluates without error, despite the dependence on the runtime
value b.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 01 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5396


Don <clugdbug yahoo.com.au> changed:

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



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: -------
May 24 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5396


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
            Summary|Invalid code with nested    |[CTFE] Invalid code with
                   |functions in CTFE           |nested functions in CTFE



https://github.com/D-Programming-Language/dmd/commit/04460186c70caa885935433138879d8684b1d14a

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 23 2011