[Issue 16301] CTFE execution of opApply keeps wrong "this" context in foreach's body

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri May 19 04:38:19 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=16301

--- Comment #6 from uplink.coder at googlemail.com ---
I figured out what is happing.

The delegate support code in the ctfe engine takes the parents scope to try and
extract a thisPtr.

in the case of walters example

struct Foo {
    int i;

    int abc() {
        void dg() { i = 0; } // value of 'this' is not known at compile time
                             // dg's direct parent is the function abc, which 
                             // does not have a this (because it's a function)
        opApply(&dg);
        return 0;
    }
}

void bar() {
    enum x = Foo().abc();
}

I am working on a solution.
It should work in a couple of days.

--


More information about the Digitalmars-d-bugs mailing list