[Issue 8062] New: UFCS and operator overloading

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 8 01:07:07 PDT 2012


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

           Summary: UFCS and operator overloading
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jens.k.mueller at gmx.de


--- Comment #0 from jens.k.mueller at gmx.de 2012-05-08 01:08:27 PDT ---
According to TDPL (p. 388, Table 12.1)
a + b
is rewritten to
a.opBinary!("+")(b) or b.opBinaryRight!("+")(a)

Considering operator overloading together with UFCS leads to the following
wrong behavior.

struct Foo {}

Foo opBinary(string op)(Foo lhs, Foo rhs) if (op == "+")
{   
    return Foo.init;
}

unittest
{   
    Foo a, b;
    a + b; // fails to compile even though it should
}

If a + b is rewritten to a.opBinary!("+")(b) first, then UFCS should rewrite it
further to opBinary!("+")(a,b). But it seems UFCS is not considered. UFCS
should be carried out when the operator is being rewritten.

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


More information about the Digitalmars-d-bugs mailing list