[Issue 1492] New: With recursive func definition, gdc evaluates too often

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 11 02:51:07 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1492

           Summary: With recursive func definition, gdc evaluates too often
           Product: DGCC aka GDC
           Version: 0.24
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: glue layer
        AssignedTo: dvdfrdmn at users.sf.net
        ReportedBy: default_357-line at yahoo.de


Take the following program:

import std.stdio, std.bind;
template SR(T...) { typedef SR!(T) delegate(T) SR; }
SR!(int) whee(int foo, int depth=1) {
  writefln(depth, ", foo is ", foo);
  return cast(SR!(int))bind(&whee, _0, depth+1).ptr;
}

void main() {
  whee(23)(42)(69);
}

What would be expected here is the following output:
1, foo is 23
2, foo is 42
3, foo is 69
What I get, however, is
1, foo is 23
1, foo is 23
2, foo is 42
1, foo is 23
1, foo is 23
2, foo is 42
3, foo is 69

It seems as if GDC evaluates the first function (1), then evaluates it again to
get the second function (1 2), then does the whole thing again to get the third
function. This, of course, slightly breaks the code. :)
 --downs


-- 



More information about the D.gnu mailing list