Weird error on nested map

Philippe Sigaud philippe.sigaud at gmail.com
Sun Jun 27 08:12:21 PDT 2010


On Sun, Jun 27, 2010 at 10:11, Simen kjaeraas <simen.kjaras at gmail.com>wrote:

> auto fn1 = ( string s ) {
>        return s;
> };
>
> auto fn2 = ( string s ) {
>        return map!fn1( [""] );
> };
>
> auto idirs = map!fn2( [""] );
>
> The above code gives the following errors:
> foo.d(114): Error: struct foo.main.Map!(fn2,string[]).Map inner struct
> Map cannot be a field
> foo.d(114): Error: struct foo.main.Map!(fn2,string[]).Map inner struct
> Map cannot be a field
>
> As far as I can see, this has to do with struct rules, but I can't see
> how to fix it. Should I file this in bugzilla?
>
>
I've had this particular error dozens of time :-(   Most of the time, it
means the function you passed to (the outer) Map is not correct, be it a
template that has trouble instantiating, a type mismatch or some frame
pointer that got lost.
In your case, I guess there is a bug somewhere concerning the passing around
of delegates. If you get rid of delegates (which is not what you want, I
know), it works:

string fn1(string s) { return s;}
auto fn2(string s) { return map!fn1([""]);}

void main()
{
    auto idirs = map!fn2([""]); // works.
}

I tried defining fn1 inside fn2, but it does not work. Too bad.


Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100627/37d0d987/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list