www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6816] New: [CTFE] nested function can't access this

reply d-bugmail puremagic.com writes:
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



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: -------
Oct 16 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6816


Don <clugdbug yahoo.com.au> changed:

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



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: -------
Oct 16 2011
prev sibling parent d-bugmail puremagic.com writes:
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



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: -------
Nov 02 2011