Thread overview
UFCS in the presence of alias this
Apr 19, 2012
Jens Mueller
Apr 19, 2012
Timon Gehr
Apr 19, 2012
Jens Mueller
Apr 19, 2012
kenji hara
Apr 19, 2012
Jens Mueller
Apr 19, 2012
Philippe Sigaud
Apr 19, 2012
Timon Gehr
Apr 19, 2012
kenji hara
April 19, 2012
Hi,

using UFCS with alias this behaves strange.
Consider

struct Foo
{
    int _member;
    alias _member this;
}

int foo(Foo f) { return f._member; }
int foo(int i) { return i; }

unittest
{
    Foo f;
    f.foo(); // which function will be called? Isn't it ambiguous?
}

Due to the alias this the function foo(int i) will be called. Is this
the indented behavior? Practically, I want UFCS to just perform a
syntactic rewrite from f.foo() to foo(f).
When using alias this you have to define the second function. Providing
only the first one results in a compile error. If you remove the alias
this things work as expected (first one needs to be defined).

I stumbled upon this problem when trying to define additional functions for a Tuple. Tuple has "alias field this" for falling back on TypeTuple's opIndex. Unfortunately,

alias Tuple!(int) Bar;
int bar(typeof(Bar.field) b) { return 1; }

unittest
{
    Bar b;
    b.bar();
}

does not work.

Jens
April 19, 2012
On 04/19/2012 11:28 AM, Jens Mueller wrote:
> Hi,
>
> using UFCS with alias this behaves strange.
> Consider
>
> struct Foo
> {
>      int _member;
>      alias _member this;
> }
>
> int foo(Foo f) { return f._member; }
> int foo(int i) { return i; }
>
> unittest
> {
>      Foo f;
>      f.foo(); // which function will be called? Isn't it ambiguous?
> }
>
> Due to the alias this the function foo(int i) will be called. Is this
> the indented behavior? Practically, I want UFCS to just perform a
> syntactic rewrite from f.foo() to foo(f).
> When using alias this you have to define the second function. Providing
> only the first one results in a compile error. If you remove the alias
> this things work as expected (first one needs to be defined).
>
> I stumbled upon this problem when trying to define additional functions
> for a Tuple. Tuple has "alias field this" for falling back on
> TypeTuple's opIndex. Unfortunately,
>
> alias Tuple!(int) Bar;
> int bar(typeof(Bar.field) b) { return 1; }
>
> unittest
> {
>      Bar b;
>      b.bar();
> }
>
> does not work.
>
> Jens

This is a bug. You can report it to:
http://d.puremagic.com/issues/
April 19, 2012
Timon Gehr wrote:
> On 04/19/2012 11:28 AM, Jens Mueller wrote:
> >Hi,
> >
> >using UFCS with alias this behaves strange.
> >Consider
> >
> >struct Foo
> >{
> >     int _member;
> >     alias _member this;
> >}
> >
> >int foo(Foo f) { return f._member; }
> >int foo(int i) { return i; }
> >
> >unittest
> >{
> >     Foo f;
> >     f.foo(); // which function will be called? Isn't it ambiguous?
> >}
> >
> >Due to the alias this the function foo(int i) will be called. Is this
> >the indented behavior? Practically, I want UFCS to just perform a
> >syntactic rewrite from f.foo() to foo(f).
> >When using alias this you have to define the second function. Providing
> >only the first one results in a compile error. If you remove the alias
> >this things work as expected (first one needs to be defined).
> >
> >I stumbled upon this problem when trying to define additional functions for a Tuple. Tuple has "alias field this" for falling back on TypeTuple's opIndex. Unfortunately,
> >
> >alias Tuple!(int) Bar;
> >int bar(typeof(Bar.field) b) { return 1; }
> >
> >unittest
> >{
> >     Bar b;
> >     b.bar();
> >}
> >
> >does not work.
> >
> >Jens
> 
> This is a bug. You can report it to: http://d.puremagic.com/issues/

It's submitted.
http://d.puremagic.com/issues/show_bug.cgi?id=7943
Thanks for your reply.

Jens
April 19, 2012
2012$BG/(B4$B7n(B19$BF|(B20:48 Jens Mueller <jens.k.mueller@gmx.de>:
> Timon Gehr wrote:
>> On 04/19/2012 11:28 AM, Jens Mueller wrote:
>> >Hi,
>> >
>> >using UFCS with alias this behaves strange.
>> >Consider
>> >
>> >struct Foo
>> >{
>> >     int _member;
>> >     alias _member this;
>> >}
>> >
>> >int foo(Foo f) { return f._member; }
>> >int foo(int i) { return i; }
>> >
>> >unittest
>> >{
>> >     Foo f;
>> >     f.foo(); // which function will be called? Isn't it ambiguous?
>> >}
>> >
>> >Due to the alias this the function foo(int i) will be called. Is this
>> >the indented behavior? Practically, I want UFCS to just perform a
>> >syntactic rewrite from f.foo() to foo(f).
>> >When using alias this you have to define the second function. Providing
>> >only the first one results in a compile error. If you remove the alias
>> >this things work as expected (first one needs to be defined).
>> >
>> >I stumbled upon this problem when trying to define additional functions for a Tuple. Tuple has "alias field this" for falling back on TypeTuple's opIndex. Unfortunately,
>> >
>> >alias Tuple!(int) Bar;
>> >int bar(typeof(Bar.field) b) { return 1; }
>> >
>> >unittest
>> >{
>> >     Bar b;
>> >     b.bar();
>> >}
>> >
>> >does not work.
>> >
>> >Jens
>>
>> This is a bug. You can report it to: http://d.puremagic.com/issues/
>
> It's submitted.
> http://d.puremagic.com/issues/show_bug.cgi?id=7943
> Thanks for your reply.
>
> Jens

Posted compiler fix: https://github.com/D-Programming-Language/dmd/pull/890

Thanks for your reporting, Jens!

Kenji Hara
April 19, 2012
kenji hara wrote:
> 2012$BG/(B4$B7n(B19$BF|(B20:48 Jens Mueller <jens.k.mueller@gmx.de>:
> > Timon Gehr wrote:
> >> On 04/19/2012 11:28 AM, Jens Mueller wrote:
> >> >Hi,
> >> >
> >> >using UFCS with alias this behaves strange.
> >> >Consider
> >> >
> >> >struct Foo
> >> >{
> >> >     int _member;
> >> >     alias _member this;
> >> >}
> >> >
> >> >int foo(Foo f) { return f._member; }
> >> >int foo(int i) { return i; }
> >> >
> >> >unittest
> >> >{
> >> >     Foo f;
> >> >     f.foo(); // which function will be called? Isn't it ambiguous?
> >> >}
> >> >
> >> >Due to the alias this the function foo(int i) will be called. Is this
> >> >the indented behavior? Practically, I want UFCS to just perform a
> >> >syntactic rewrite from f.foo() to foo(f).
> >> >When using alias this you have to define the second function. Providing
> >> >only the first one results in a compile error. If you remove the alias
> >> >this things work as expected (first one needs to be defined).
> >> >
> >> >I stumbled upon this problem when trying to define additional functions for a Tuple. Tuple has "alias field this" for falling back on TypeTuple's opIndex. Unfortunately,
> >> >
> >> >alias Tuple!(int) Bar;
> >> >int bar(typeof(Bar.field) b) { return 1; }
> >> >
> >> >unittest
> >> >{
> >> >     Bar b;
> >> >     b.bar();
> >> >}
> >> >
> >> >does not work.
> >> >
> >> >Jens
> >>
> >> This is a bug. You can report it to: http://d.puremagic.com/issues/
> >
> > It's submitted.
> > http://d.puremagic.com/issues/show_bug.cgi?id=7943
> > Thanks for your reply.
> >
> > Jens
> 
> Posted compiler fix: https://github.com/D-Programming-Language/dmd/pull/890
> 
> Thanks for your reporting, Jens!

Fabulous. Thanks a lot.

Jens
April 19, 2012
Jens:
>> It's submitted. http://d.puremagic.com/issues/show_bug.cgi?id=7943

(something like, one hour passes)

Kenji:
> Posted compiler fix: https://github.com/D-Programming-Language/dmd/pull/890

Man, you're wonderful Kenji. You never cease to amaze me. Your ability to correct bugs is borderline incredible.
April 19, 2012
2012$BG/(B4$B7n(B20$BF|(B0:56 Philippe Sigaud <philippe.sigaud@gmail.com>:
> Jens:
>>> It's submitted. http://d.puremagic.com/issues/show_bug.cgi?id=7943
>
> (something like, one hour passes)
>
> Kenji:
>> Posted compiler fix: https://github.com/D-Programming-Language/dmd/pull/890
>
> Man, you're wonderful Kenji. You never cease to amaze me. Your ability to correct bugs is borderline incredible.

Thanks.

Kenji Hara
April 19, 2012
On 04/19/2012 05:56 PM, Philippe Sigaud wrote:
> Jens:
>>> It's submitted.
>>> http://d.puremagic.com/issues/show_bug.cgi?id=7943
>
> (something like, one hour passes)
>

I counted 26 minutes.

> Kenji:
>> Posted compiler fix:
>> https://github.com/D-Programming-Language/dmd/pull/890
>
> Man, you're wonderful Kenji. You never cease to amaze me. Your ability
> to correct bugs is borderline incredible.