Thread overview
[Issue 6816] New: [CTFE] nested function can't access this
Oct 16, 2011
dawg@dawgfoto.de
Oct 16, 2011
Don
Nov 02, 2011
Walter Bright
October 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6816

           Summary: [CTFE] nested function can't access this
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dawg@dawgfoto.de


--- Comment #0 from dawg@dawgfoto.de 2011-10-16 00:20:10 PDT ---
struct S
{
    size_t foo()
    {
        size_t nested()
        {
            return value + 1;
        }
        return nested();
    }

    size_t value;
}

enum s = S().foo();

----

It seems as if checking callers in ThisExp::interpret would work.

    while (istate && !istate->localThis)
        istate = istate->caller;

Errors for a wrong 'this' will/should be detected during semantic.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6816


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

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


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2011-10-16 14:03:28 PDT ---
Another test case, where it's a delegate literal instead of a nested function.

struct S {
    size_t foo() {
        return (){ return value+1; }();
    }
    size_t value;
}

enum s = S().foo();

Incidentally if you make 'foo' static, the error message is poor: the message "need this to access member 'value'" is generated in the glue layer (SymbolExp::toElem, in e2ir.c). It should be detected in the semantic pass instead.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6816


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-11-02 13:07:32 PDT ---
https://github.com/D-Programming-Language/dmd/commit/3055cc6a8b36a2e00c270b0e48e1d1bd2c931f37

https://github.com/D-Programming-Language/dmd/commit/72e750209b370b66157f320d3517c5816a3951d7

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