www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14392] New: Operator overload is shadowed by "alias this"


          Issue ID: 14392
           Summary: Operator overload is shadowed by "alias this"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: maximzms gmail.com

In the following code `alias this` should not be used since there is method
`Boo.opBinary` that takes argument of type `Foo` explicitly.

import std.stdio;

struct Foo
    int v;

    auto opBinaryRight(string op)(int lhs) if (op == "*")
        writeln("int * Foo");
        return Boo(lhs * v);

struct Boo
    int v;
    alias v this;

    auto opBinary(string op)(Foo rhs) if (op == "*")
        writeln("Boo * Foo");
        return Boo(v * rhs.v);

void main(string[] args)
    Boo(1) * Foo(2);

The output should be "Boo * Foo" regardless whether there is `alias this` or
However it is "int * Foo" with `alias this` line and "Boo * Foo" without it.
Tested with DMD v2.067.0

Apr 01 2015