Bug 11290 – Usage of alias in opBinary on object that is passed in leads to unexpected behaviour.

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-17T18:25:55Z
Last change time
2024-12-13T18:13:14Z
Assigned to
No Owner
Creator
Nicolas F.
Moved to GitHub: dmd#18700 →

Comments

Comment #0 by ajidala — 2013-10-17T18:25:55Z
Using alias in opBinary onto the object that is passed in incorrectly aliases to "this" instead of the object passed in. It's best illustrated with some code: import std.stdio; class Foo { int kek; this(int val) { this.kek = val; } Foo opBinary(string op)(Foo bar) if (op == "*") { alias k1 = this.kek; alias k2 = bar.kek; writefln("k1 = %s, this.kek = %s", k1, this.kek); writefln("k2 = %s, bar.kek = %s", k2, bar.kek); Foo f = new Foo(k1 * k2); return f; } } void main() { Foo f1 = new Foo(2); Foo f2 = new Foo(5); Foo f3 = f1 * f2; } The output is: k1 = 2, this.kek = 2 k2 = 2, bar.kek = 5 The expected output would be: k1 = 2, this.kek = 2 k2 = 5, bar.kek = 5
Comment #1 by robert.schadek — 2024-12-13T18:13:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18700 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB