Re: UFCS doesn't work in some cases
On Tuesday, 9 September 2014 at 18:46:31 UTC, ketmar via Digitalmars-d-learn wrote: UFCS is not working for nested functions. this is not a bug, it was designed this way. the same for 'with', i believe. Apparently it is a bug that UFCS doesn't work with 'with' statement. https://issues.dlang.org/show_bug.cgi?id=10349 there is rationale. see http://dlang.org/function.html, UFCS section. Must have missed it before, thanks.
Re: UFCS doesn't work in some cases
On Wed, 10 Sep 2014 13:58:18 + Danyal Zia via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Apparently it is a bug that UFCS doesn't work with 'with' statement. my fault, i thought that it shouldn't. i'm still not Guru. too bad, will work. ;-) signature.asc Description: PGP signature
UFCS doesn't work in some cases
Hi, I don't know if this has been mentioned before, but I found two strange cases where UFCS doesn't work. Case # 1: When the functions for UFCS are defined inside main scope class Rect { int x = 20; int y = 20; } void main() { import std.stdio : writeln; int area(Rect rect) { return rect.x * rect.y; } auto rect = new Rect; rect.area.writeln; // Error: no property 'area' for type 'main.Rect' } Put that 'area' definition outside the main body and it works fine. Case # 2: When using UFCS in 'with' scope class Rect { int x = 20; int y = 20; } int area(Rect rect) { return rect.x * rect.y; } void main() { import std.stdio : writeln; auto rect = new Rect; with(rect) { area.writeln; // Error: function main.area (Rect rect) is not callable using argument types () } } As far as I know, UFCS are designed to make it easy to extend the class for specific applications, however, without the ability to use UFCS for those cases, it limits its usefulness. Are these oversights/bugs? Or is their any rationale behind the decision to not implement UFCS for them? Danyal
Re: UFCS doesn't work in some cases
On Tue, 09 Sep 2014 17:58:14 + Danyal Zia via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Case # 1: When the functions for UFCS are defined inside main scope UFCS is not working for nested functions. this is not a bug, it was designed this way. the same for 'with', i believe. oversights/bugs? Or is their any rationale behind the decision to not implement UFCS for them? there is rationale. see http://dlang.org/function.html, UFCS section. signature.asc Description: PGP signature
Re: UFCS doesn't work in some cases
On Tuesday, 9 September 2014 at 17:58:16 UTC, Danyal Zia wrote: As far as I know, UFCS are designed to make it easy to extend the class for specific applications, however, without the ability to use UFCS for those cases, it limits its usefulness. Are these oversights/bugs? Or is their any rationale behind the decision to not implement UFCS for them? Danyal The reason why local symbols are not considered by UFCS, is to avoid unexpected name conflicts. Stated at the very bottom of: http://dlang.org/function.html