www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 655] New: Operator overload uses opIndex instead of opIndexAssign

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=655

           Summary: Operator overload uses opIndex instead of opIndexAssign
           Product: D
           Version: 0.176
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: brunodomedeiros+bugz gmail.com


In an array assignment expression, operator overload uses opIndex instead of
opIndexAssign.
----------
import std.stdio;

struct Moo {
  void opIndex(int i, int i2) { 
    writefln("opIndex:", i, i2);
  }
}

int main(char[][] args) {
  Moo m = *new Moo();
  m[0, 42]; // uses opIndex , ok
  m[0] = 42; // uses opIndex instead of opAssign, not ok according to spec

  return 0;
}


-- 
Dec 06 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=655





------- Comment #1 from brunodomedeiros+bugz gmail.com  2006-12-06 08:43 -------
Agh, read the comment above as:
  m[0] = 42; // uses opIndex instead of opIndexAssign, not ok according to spec


-- 
Dec 06 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=655





------- Comment #2 from jarrett.billingsley gmail.com  2006-12-06 09:18 -------
 import std.stdio;
 
 struct Moo {
   void opIndex(int i, int i2) { 
     writefln("opIndex:", i, i2);
   }
 }
 
 int main(char[][] args) {
   Moo m = *new Moo();
   m[0, 42]; // uses opIndex , ok
   m[0] = 42; // uses opIndex instead of opAssign, not ok according to spec
 
   return 0;
 }
 

When I compile that snippet in 0.176, I get the error: dtest.d(134): Error: operator [] assignment overload with opIndex(i, value) deprecated, use opIndexAssign(value, i) Is that what you mean? Or does it compile for you? I think it's a vestige of some _very_ old operator overloading behavior, Walter probably missed it. --
Dec 06 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=655


brunodomedeiros+bugz gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #3 from brunodomedeiros+bugz gmail.com  2006-12-07 13:23 -------
My mistake, I was compiling with -d (allow deprecated) and didn't notice it.


-- 
Dec 07 2006