digitalmars.D.learn - UFCS doesn't work in some cases
- Danyal Zia (43/43) Sep 09 2014 Hi,
- ketmar via Digitalmars-d-learn (6/10) Sep 09 2014 On Tue, 09 Sep 2014 17:58:14 +0000
- Danyal Zia (6/11) Sep 10 2014 Apparently it is a bug that UFCS doesn't work with 'with'
- ketmar via Digitalmars-d-learn (5/7) Sep 10 2014 On Wed, 10 Sep 2014 13:58:18 +0000
- Mathias LANG (2/10) Sep 09 2014 Stated at the very bottom of: http://dlang.org/function.html
Hi, I don't know if this has been mentioned before, but I found two strange cases where UFCS doesn't work. 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. 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
Sep 09 2014
On Tue, 09 Sep 2014 17:58:14 +0000 Danyal Zia via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:scopeUFCS 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=20 not implement UFCS for them?there is rationale. see http://dlang.org/function.html, UFCS section.
Sep 09 2014
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=10349there is rationale. see http://dlang.org/function.html, UFCS section.Must have missed it before, thanks.
Sep 10 2014
On Wed, 10 Sep 2014 13:58:18 +0000 Danyal Zia via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Apparently it is a bug that UFCS doesn't work with 'with'=20 statement.my fault, i thought that it shouldn't. i'm still not Guru. too bad, will work. ;-)
Sep 10 2014
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? DanyalThe 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
Sep 09 2014