Bug 2327 – opDot() should work as expected with operator overloading.
Status
RESOLVED
Resolution
WONTFIX
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-09-02T13:27:00Z
Last change time
2015-06-09T01:20:08Z
Keywords
spec
Assigned to
nobody
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2008-09-02T13:27:16Z
struct Foo {
uint i;
Foo opAdd(uint input) {
return Foo(i + input);
}
}
struct Bar {
Foo foo;
Foo opDot() {
return foo;
}
}
void main() {
Bar bar;
auto result = bar.opAdd(5); //Works.
auto result2 = bar + 5; //Compile time error: test.d|22|Error: incompatible types for ((bar) + (5)): 'Bar' and 'int'|
}
IMHO, this behavior is incorrect. Operator overloading is supposed to be semantically equivalent to calling the method with the overload name, i.e. a + b is supposed to be the exact semantic equivalent of a.opAdd(b) if a and b are class or struct objects with overloaded opAdd. In this case, it clearly isn't.
Comment #1 by dsimcha — 2010-08-15T21:28:28Z
Is opDot() going to be deprecated once alias this is better-debugged? I see no reason why it shouldn't be. If so, I'll mark this as wontfix.
Comment #2 by dsimcha — 2011-08-27T07:37:14Z
I'm resolving this as WONTFIX because opDot has been superseded by alias this and is no longer documented and scheduled for deprecation.