[Issue 3188] remove opIndexAssign from the language

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 17 10:24:57 PDT 2009


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


Stewart Gordon <smjg at iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg at iname.com
           Platform|Other                       |All




--- Comment #1 from Stewart Gordon <smjg at iname.com>  2009-07-17 10:24:56 PDT ---
(In reply to comment #0)
> Despite being redundant, my main gripe with opIndexAssign is that it can even
> get in the way. For instance:

opIndexAssign isn't redundant, just as property setters aren't redundant.

>     // This requires opIndexAssign, but for no good reason
>     //a[1, 1] = 42;

Given that opIndexAssign doesn't occur in your code, removing opIndexAssign
from the language isn't going to magically make this work.

Here's the compiler output (DMD 2.031 Win):
----------
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd bz3188.d
bz3188.d(28): Error: operator [] assignment overload with opIndex(i, value)
illegal, use opIndexAssign(value, i)
----------

Really, the problem is that opIndex is only meant to work on op=, ++ and --,
not = itself.

http://www.digitalmars.com/d/2.0/operatoroverloading.html
"Note: To use array index overloading with the op=, ++, or -- operators, have
the opIndex function return a reference type. This reference is then used as
the lvalue for those operators."

The way resolving = ought to work:
- first look for a matching opIndexAssign
- if none, look for an opIndex with a ref return

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