Bug 1492 – With recursive func definition, gdc evaluates too often
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-09-11T04:51:00Z
Last change time
2015-06-09T05:14:52Z
Assigned to
dvdfrdmn
Creator
default_357-line
Comments
Comment #0 by default_357-line — 2007-09-11T04:51:06Z
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