digitalmars.D.bugs - [Issue 11048] New: Default arguments not taken into account when being called by pure functions
- d-bugmail puremagic.com (28/28) Sep 15 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11048
- d-bugmail puremagic.com (17/17) Sep 16 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11048
- d-bugmail puremagic.com (15/15) Sep 16 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11048
http://d.puremagic.com/issues/show_bug.cgi?id=11048 Summary: Default arguments not taken into account when being called by pure functions Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: jmdavisProg gmx.com PDT --- int x = 7; void foo() pure { // Does not detect use of mutable global and compiles when it shouldn't. bar(); // Correctly detects the use of a mutable global and gives an error baz(x); } void bar(int a = x) pure {} void baz(int a) pure {} void main() {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 15 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11048 Andrej Mitrovic <andrej.mitrovich gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich gmail.com 08:48:37 PDT --- So should the declaration of such a function be denied if it's pure, or should only calls be denied where a global is used? E.g.: // 1. ban this declaration? void bar(int a = x) pure {} // 2. or just this call? bar(); bar(1); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 16 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11048 PDT --- The default argument is only a problem if the pure function is called from a pure function. It's perfectly fine if it's called from an impure one. The problem is not that the default argument references a global but that the caller does not detect that the default argument of the function it's calling is a global. So, the caller does not detect that the call violates purity. The simplest solution is probably to ban the declaration, because then the caller doesn't have to worry about whether the pure function that it's calling has any default arguments which would violate the purity of the caller, but ideally, it's just the call which would be illegal, because the default argument is just fine so long as the caller isn't pure. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 16 2013