https://issues.dlang.org/show_bug.cgi?id=13897
Kenji Hara <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #2 from Kenji Hara <[email protected]> --- (In reply to bearophile_hugs from comment #0) > This compiles with no errors in dmd 2.067alpha: It's an intentional language change. Until 2.066, the nested function foo had been deduced as a strong purity function. But if foo is declared in struct or class scope, it had been deduced as a weak purity function. That was inconsistent. // 2.066 and earlier void main() { int x; void foo() pure { // wrongly deduced as strong purity x++; // modifying enclosing scope via context pointer was rejected. } } struct S { int x; void foo() pure { // weak purity x++; // OK } } In git-head, a nested function without any type qualifiers is deduced to weak purity so it has a hidden mutable context pointer, and the semantics is consistent with member functions. // 2.067alpha void main() { int x; void foo() pure { // deduced as weak purity, so x++; // modifying enclosing scope via context pointer is accepted. } void bar() immutable pure { // deduced as strong purity x++; // NG } } struct S { int x; void foo() pure { // weak purity x++; } void bar() immutable pure { // strong purity x++; // NG } } See also issue 9148 comments for more detail. --
