Bug 13729 – [REG2.067a] One not detected case of not purity

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-11-13T12:44:00Z
Last change time
2015-06-17T21:01:28Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-11-13T12:44:47Z
This compiles with no errors, but main() is not pure: int x; void main() pure { static void foo() { x++; } foo(); } This correctly gives an error: int x; void bar() { x++; } void main() pure { bar(); // Error }
Comment #1 by k.hara.pg — 2015-02-27T13:45:14Z
Comment #2 by github-bugzilla — 2015-02-28T02:09:54Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3a9a56bce0d595fbe538946321e2fb8692711386 fix Issue 13729 - One not detected case of not purity https://github.com/D-Programming-Language/dmd/commit/8b3bd7381a82dac630f5a8374618caf5a3b8ae98 Merge pull request #4447 from 9rnsr/fix13729 [REG2.067a] Issue 13729 - One not detected case of not purity
Comment #3 by bearophile_hugs — 2015-02-28T10:54:09Z
Now this code: int x; void main() pure { static void foo() { x++; } foo(); } Gives: test.d(4,9): Error: pure function 'D main' cannot access mutable static data 'x' I think a more precise error message should say that the pure function main() can't call the impure static function foo(), and foo() can't be pure because it writes static data. This program shows that foo() doesn't need to be annotated with "pure" for the code to compile: int x; void main() pure { static void foo() { } foo(); }
Comment #4 by github-bugzilla — 2015-02-28T21:07:30Z
Commit pushed to 2.067 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/fe6729a9465c628e48712d9c3c7a722d4d100f1d Merge pull request #4447 from 9rnsr/fix13729 [REG2.067a] Issue 13729 - One not detected case of not purity Conflicts: src/expression.c
Comment #5 by github-bugzilla — 2015-04-11T12:24:45Z
Comment #6 by github-bugzilla — 2015-06-17T21:01:28Z