Bug 10254 – Purity correctness is broken with constructor

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-03T07:57:00Z
Last change time
2013-07-13T23:52:46Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
zan77137

Comments

Comment #0 by zan77137 — 2013-06-03T07:57:24Z
This code doesn't work: --------------- int a; auto foo() pure { static class A { this(){a = 2;} } return new A; // This line should be a compilation error. } void main() { a = 1; auto x = foo(); // Pure function doesn't change any global variables. assert(a == 1); // Thefore, global variable `a` never changes. }
Comment #1 by simen.kjaras — 2013-06-03T08:34:47Z
Interestingly, this fails to compile: int a; auto foo() pure { return (){a=2;} // Error: pure function 'foo.foo.__lambda1' // cannot access mutable static data 'a' } void main() { a = 1; auto x = foo(); x(); assert(a == 1); } This behavior indicates to me that it is in fact A's constructor that should be a compilation error. It is a Voldemort type anyway, so how are you ever going to call that constructor safely?
Comment #2 by k.hara.pg — 2013-06-05T02:25:08Z
Comment #3 by github-bugzilla — 2013-06-05T10:37:12Z
Commit pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/e1cbd173bc1bdaa62a584f22df4cba7e3ba1ec8f Change the Exception/Error constructors to @safe pure nothrow This is a druntime fix-up for the compiler bug 10254.
Comment #4 by github-bugzilla — 2013-06-27T18:53:28Z
Comment #5 by github-bugzilla — 2013-07-02T08:07:10Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6e6310d20dfa75c1d56b33be66056e9554092e0c fix Issue 10254 - Purity correctness is broken with constructor https://github.com/D-Programming-Language/dmd/commit/64e05bb8862c1cd33d61900957dc128d1c8d4712 Merge pull request #2135 from 9rnsr/fix10254 Issue 10254 - Purity correctness is broken with constructor
Comment #6 by k.hara.pg — 2013-07-13T23:52:46Z
*** Issue 6320 has been marked as a duplicate of this issue. ***