Bug 1367 – D 2.003 breaks foreach looping over delegate
Status
RESOLVED
Resolution
WORKSFORME
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-07-23T09:06:00Z
Last change time
2015-06-09T01:14:14Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2007-07-23T09:06:57Z
Slightly modified example from http://www.digitalmars.com/d/statement.html#ForeachStatement (to use a delegate reference instead of opApply:
import std.stdio;
class Foo
{
uint array[2];
int looper(int delegate(ref uint) dg)
{
int result = 0;
for (int i = 0; i < array.length; i++)
{
result = dg(array[i]);
if (result)
break;
}
return result;
}
void run()
{
foreach (uint u; &looper)
writefln("%d", u);
}
}
void main()
{
Foo a = new Foo();
a.array[0] = 73;
a.array[1] = 82;
a.run();
}
Compiler prints:
foreach_delegate.d(22): Error: foreach: int function(int delegate(ref uint) dg)* is not an aggregate type
This worked in DMD 2.002. opApply features seem unaffected.