June 27, 2010 Weird error on nested map | ||||
---|---|---|---|---|
| ||||
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? -- Simen |
June 27, 2010 Re: Weird error on nested map | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen kjaeraas Attachments:
| On Sun, Jun 27, 2010 at 10:11, Simen kjaeraas <simen.kjaras@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
|
Copyright © 1999-2021 by the D Language Foundation