digitalmars.D.bugs - [Issue 2804] New: Impure nested functions should be legal inside pure functions[patch included]
- d-bugmail puremagic.com (40/40) Apr 06 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2804
- d-bugmail puremagic.com (11/11) Apr 06 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2804
- d-bugmail puremagic.com (9/9) Apr 17 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2804
http://d.puremagic.com/issues/show_bug.cgi?id=2804 Summary: Impure nested functions should be legal inside pure functions[patch included] Product: D Version: 2.027 Platform: PC OS/Version: Windows Status: NEW Keywords: patch, rejects-valid Severity: enhancement Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: clugdbug yahoo.com.au Example contributed by bearophile. ------ import std.c.stdio: printf; import std.conv: toInt; pure int double_sqr(int x) { int y, z; void do_sqr() { y *= y; } y = x; do_sqr(); z += y; y = x; do_sqr(); z += y; return z; } void main(string[] args) { int x = args.length == 2 ? toInt(args[1]) : 10; int y = double_sqr(x) + double_sqr(x); printf("4 * x * x = %d\n", y); } -------- pure_test3.d(...): Error: pure function 'double_sqr' cannot call impure function 'do_sqr' pure_test3.d(...): Error: pure function 'double_sqr' cannot call impure function 'do_sqr' --
Apr 06 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2804 Created an attachment (id=315) --> (http://d.puremagic.com/issues/attachment.cgi?id=315&action=view) patch for 2804 This allows pure functions to call their own nested functions (even if such functions aren't marked as pure), but prevents nested functions inside pure functions from (1) calling impure functions and (2) accessing static variables. --
Apr 06 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2804 clugdbug yahoo.com.au changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED Fixed DMD2.028 --
Apr 17 2009