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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue May 23 16:59:20 PDT 2017


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

--- Comment #9 from Eyal <eyal at weka.io> ---
In the code review I saw that the PR changed the CTFE to use dynamic scoping
lookup instead of lexical scoping so after much IRC back and forth I eventually
managed to distill the problematic example to:

@safe:

unittest {
    struct Foo {
    @safe:
        int i;
        int whoami() { return i; }
        int call(int delegate() @safe dlg) {
            return dlg();
        }
    }
    int func() {
        auto foo1 = Foo(1);
        auto foo2 = Foo(2);
        assert(1 == foo2.call(&foo1.whoami));
        return 0;
    }
    enum F = func();
}

--


More information about the Digitalmars-d-bugs mailing list