www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11094] New: Disuniform error messages with overloaded + and ^ operators

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

           Summary: Disuniform error messages with overloaded + and ^
                    operators
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2013-09-22 04:41:14 PDT ---
With DMD 2.064alpha this code gives no errors, it seems correct:


struct Foo {
    Foo opBinary(string op)(in Foo r) inout if (op == "+") {
        return Foo();
    }
    Foo opBinary(string op)(in Foo r) inout if (op == "^") {
        return Foo();
    }
}
void main() {
    const x = Foo();
    auto r1 = x + Foo();
    auto r2 = x ^ Foo();
}


But if I forget the inouts:

struct Foo {
    Foo opBinary(string op)(in Foo r) if (op == "+") {
        return Foo();
    }
    Foo opBinary(string op)(in Foo r) if (op == "^") {
        return Foo();
    }
}
void main() {
    const x = Foo();
    auto r1 = x + Foo();
    auto r2 = x ^ Foo();
}


DMD gives:

test.d(11): Error: incompatible types for ((x) + (Foo())): 'const(Foo)' and
'Foo'
test.d(12): Error: 'x' is not of integral type, it is a const(Foo)
test.d(12): Error: 'Foo()' is not of integral type, it is a Foo

I suggest:
- To give only one error message for the "^" case;
- To give the same error messages for both "+" and "^";
- Perhaps the error message could explain better the problem, or/and perhaps it
could suggest the use of 'inout'.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2013