www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - UCFS does not work for nested functions?

reply "Steffen Wenz" <spam steffenwenz.de> writes:
Hi,

Just noticed that using UFCS does not work for nested functions, 
and was wondering whether that's intended, and what the rationale 
behind it is:


class X {
	void foo() {}
}

void main() {
	// moving bar to module scope solves the error below
	void bar(X x) {}

	X x;
	x.foo(); // ok
	bar(x); // ok
	x.bar(); // Error: no property 'bar' for type 'nested.X'
}
May 18 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
Steffen Wenz:

 Just noticed that using UFCS does not work for nested functions,
Right.
 and was wondering whether that's intended, and what the 
 rationale behind it is:
Currently it's intended. Because doing otherwise causes other problems with struct/class member functions. Perhaps there are ways to design around this problem, but so far no one has suggested a good way to design it (and the good Kenji has worked on this problem, so probably there are no simple solutions). Once you understand this problem space well, if you find a good design solution you can submit it to Bugzilla. Bye, bearophile
May 18 2014