Thread overview
[Issue 277] New: Named mixin operator resolution
Aug 03, 2006
d-bugmail
Aug 14, 2006
d-bugmail
Aug 16, 2006
d-bugmail
Aug 16, 2006
Bruno Medeiros
Aug 16, 2006
d-bugmail
Aug 18, 2006
Bruno Medeiros
August 03, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=277

           Summary: Named mixin operator resolution
           Product: D
           Version: 0.163
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: xergen@hotmail.com


template TestMixin(){
    void opCall()    {
    }

    void opCatAssign(uint val)    {
    }
}

class Test{
    mixin TestMixin bar;

    void foo(){
    //bar(); // doesn't work !?!?
    bar.opCall(); // works
    //bar ~= 3; // doesn't work
    bar.opCatAssign(3); // works
    }
}

void main(char[][] args){
    Test t = new Test();
    t.bar ~= 3; // works
    t.bar(); // works
    t.bar.opCall(); // works

    t.foo();
}

May seem trivial, but its actually pretty important for some friendly things im
working on.  Mixin operators can't be called from within the scope using the
mixin? Odd :) Thanks.
PS. You're my hero Walter.


-- 

August 14, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=277





------- Comment #1 from xergen@hotmail.com  2006-08-14 00:21 -------
Also, operator selection doesnt happen with names.
for example:

template Foo()
{
 void opAddAssign(int x)
 {
 }
}

class Bar
{
 mixin Foo a;
 mixin Foo b;
}

Bar b;
bar.a += 2; // ambiguouity error
bar.a.opAddAssign(2); // works


-- 

August 16, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=277


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Priority|P2                          |P4




------- Comment #2 from bugzilla@digitalmars.com  2006-08-15 23:46 -------
This is not a bug because operator overloading needs an object, and a mixin is not an object. It's working as designed. I've changed this to an enhancement request.


-- 

August 16, 2006
d-bugmail@puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=277
> 
>            Summary: Named mixin operator resolution
>            Product: D
>            Version: 0.163
>           Platform: PC
>         OS/Version: Windows
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: DMD
>         AssignedTo: bugzilla@digitalmars.com
>         ReportedBy: xergen@hotmail.com
> 
> 
> template TestMixin(){
>     void opCall()    {
>     }
> 
>     void opCatAssign(uint val)    {
>     }
> }
> 
> class Test{
>     mixin TestMixin bar;
> 
>     void foo(){
>     //bar(); // doesn't work !?!?
>     bar.opCall(); // works
>     //bar ~= 3; // doesn't work
>     bar.opCatAssign(3); // works
>     }
> }
> 
> void main(char[][] args){
>     Test t = new Test();
>     t.bar ~= 3; // works
>     t.bar(); // works
>     t.bar.opCall(); // works
> 
>     t.foo();
> }
> 
> May seem trivial, but its actually pretty important for some friendly things im
> working on.  Mixin operators can't be called from within the scope using the
> mixin? Odd :) Thanks.
> PS. You're my hero Walter.
> 
> 

Not sure if it will be an useful workaround but using "this" works:
----
class Test{
  mixin TestMixin bar;

  void foo(){
    this.bar(); // works
    bar.opCall();
    this.bar ~= 3; // works
    bar.opCatAssign(3);
  }
}

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
August 16, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=277





------- Comment #3 from xergen@hotmail.com  2006-08-16 16:56 -------
thanks for the workaround Bruno, though I'm afraid that would still be subject to the problems with operator resolution in my comment :(  Works great if you've only got one mixin however :)

As far as it being an enhancement, I can see your judgement there.  But I would still think the second issue is a bug, as it's simply ignoring the mixin name, which doesn't seem to make much sense to me.


-- 

August 18, 2006
d-bugmail@puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=277
> 
> 
> 
> 
> 
> ------- Comment #3 from xergen@hotmail.com  2006-08-16 16:56 -------
> thanks for the workaround Bruno, though I'm afraid that would still be subject
> to the problems with operator resolution in my comment :(  Works great if
> you've only got one mixin however :)
> 
> As far as it being an enhancement, I can see your judgement there.  But I would
> still think the second issue is a bug, as it's simply ignoring the mixin name,
> which doesn't seem to make much sense to me.
> 
> 

Dude, don't reply in the bugzilla to posts made (solely) in the NG. :P

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D