2013/7/2 deadalnix <deadal...@gmail.com> > On Tuesday, 2 July 2013 at 08:16:38 UTC, Jonathan M Davis wrote: > >> On Tuesday, July 02, 2013 09:35:38 monarch_dodra wrote: >> >>> Coming back from learn here. There was an example where somebody >>> "accidentally" called a constructor via UFCS. I am kind of >>> surprised that it worked. I thought UFCS was for functions only, >>> and that constructors (specifically) were off limits. >>> >>> Am I mistaken? Is UFCS explicitly allowed for constructors? Or >>> did we kind of forget to take it into account? >>> >> >> I'm not sure that it was ever decided one way or the other so much as >> happened >> into being due to how UFCS was implemented. I know that it's come up >> before, >> and folks were arguing on both sides. Personally, I think that it's a >> horrible >> idea. >> >> - Jonathan M Davis >> > > We are 2. that is horrible. >
I don't know what design decision had been there about it. Historically, there's no restriction against UFCS-callable entity. With 2.030 (released on May 11, 2009) and git head, following code completely works. void foo(int[]) {} void bar(T)(T) {} struct Foo { int[] x; } struct Bar { this(int[]) {} } struct Baz { static opCall(int[]) { return 0; } } int[] function(int[]) fp; int[] delegate(int[]) dg; struct Functor { int opCall(int[]) { return 0; } } Functor fn; void main() { fp = function(int[] x){ return x; }; dg = delegate(int[] x){ return x; }; int[] a; a.foo(); a.bar(); auto x1 = a.Foo(); auto x2 = a.Bar(); auto x3 = a.Baz(); a.fp(); a.dg(); a.fn(); } While improvement of dmd front-end code, I didn't touch it. Yes, I did never designed it... Kenji Hara