www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Weird error on nested map

reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
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
Jun 27 2010
parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
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
Jun 27 2010