[Issue 9257] New: [ER] New optional "operator" keyword to validate magic functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 2 07:44:55 PST 2013


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

           Summary: [ER] New optional "operator" keyword to validate magic
                    functions
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2013-01-02 07:44:54 PST ---
Rationale:
When writing an operator, one might accidentally typo, use the wrong signature,
use the wrong name, use an un-existing name etc. Because the compiler relies on
only checking function names, the end user has no way to check if the code is
correct, appart from "noticing" that calling the operator doesn't work.

This can become quite clumsy once the more complicated things, like
"opIndexOpAssign" (or was that "opOpIndexAssign" ?) get involved.

Description:
When writing a function with a "magic" name, one can prefix it with the keyword
operator. If that function name doesn't match any of the special functions,
with the correct amount of arguments, then a compile error is thrown:

//----
struct S
{
  operator opBinary(string op)(S rhs); //Fine
  operator opBinary(string op)(S rhs1, S rhs2); //Error, wrong number of
arguments
  operator opOpBinary(string op)(Type rhs); //Error, did you mean opOpAssign?
  operator opcmp(Type rhs); //Error, did you mean opCmp?
  static bool opEquals(S s1, S s2); //Error, opEquals cannot be declared as
static
}
//----

This would help with keeping in line with D's safety standard, in particular,
the override keyword.

(from the discussion:
http://forum.dlang.org/thread/iubdngjksicwxugrqesc@forum.dlang.org)

Also want to point out: This bug has even made it into phobos.

-- 
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