Bug 14392 – Operator overload is shadowed by "alias this"

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-02T06:45:59Z
Last change time
2024-12-13T18:41:47Z
Assigned to
No Owner
Creator
Maksim Zholudev
Moved to GitHub: dmd#18968 →

Comments

Comment #0 by maximzms — 2015-04-02T06:45:59Z
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
Comment #1 by dlang-bugzilla — 2015-04-05T03:59:06Z
FWIW this code fails to compile before 2.064 (specifically, before this PR: https://github.com/D-Programming-Language/dmd/pull/1409)
Comment #2 by robert.schadek — 2024-12-13T18:41:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18968 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB