[Issue 14392] New: Operator overload is shadowed by "alias this"
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Apr 1 23:45:59 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14392
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 at puremagic.com
Reporter: maximzms at 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
not.
However it is "int * Foo" with `alias this` line and "Boo * Foo" without it.
Tested with DMD v2.067.0
--
More information about the Digitalmars-d-bugs
mailing list