[Issue 15650] New: Closure variable access broken in contracts

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Feb 6 12:34:25 PST 2016


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

          Issue ID: 15650
           Summary: Closure variable access broken in contracts
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: code at klickverbot.at

The following test case, an adapted version of runnable/test10981.d, fails
using DMD 2.070 (OS X, but that's irrelevant):

---
auto foo(int i)
{
    class X1
    {
        void in_nested() in {
            import core.stdc.stdio;
            printf("%d\n", i);
            assert(i);
        } body {}
    }

    return new X1;
}

void main() {
    auto a = foo(1234);
    a.in_nested();
}
---

The problem seems to be that the frontend assumes that variable references from
contracts *never* make the variable in question a closureVar, irrespective of
whether the variable accessed is in the direct parent function or further up
the chain.


[1]
https://github.com/D-Programming-Language/dmd/blob/9d1edd1e78031e5760cc7cf923dd0bf9b1f8e7e6/src/declaration.d#L2232

--


More information about the Digitalmars-d-bugs mailing list