[Issue 2327] New: opDot() should work as expected with operator overloading.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 2 11:27:18 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2327

           Summary: opDot() should work as expected with operator
                    overloading.
           Product: D
           Version: 2.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: minor
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: dsimcha at yahoo.com


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.


-- 



More information about the Digitalmars-d-bugs mailing list