[Issue 9148] 'pure' is broken
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jan 26 06:07:38 PST 2015
https://issues.dlang.org/show_bug.cgi?id=9148
--- Comment #11 from Kenji Hara <k.hara.pg at gmail.com> ---
I'm adjusting the implicit pure annotation behavior for nested functions in:
https://github.com/D-Programming-Language/dmd/pull/4344
If the nested function is a template, attribute inference is preferred and pure
will be added only when the function is accessing enclosing pure function
context.
auto foo() pure {
int x;
auto bar()() { // template function bar can be impure by default
// bar will be forced to get weak purity, only when it's trying
// to access enclosing pure function context.
//x = 1;
// otherwise, bar can call impure functions and then
// it will be inferred to impure.
impureFuncCall().
}
}
Once nested template function is inferred to impure, it cannot access enclosing
pure context anymore.
auto foo() pure {
int x;
auto bar()() {
impureFuncCall().
x = 1; // Error: impure function 'bar' cannot access variable 'x'
// declared in enclosing pure function 'foo'
}
}
--
More information about the Digitalmars-d-bugs
mailing list