[Issue 9498] Range violation using AA

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 8 21:52:35 PDT 2013


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


Kenji Hara <k.hara.pg at gmail.com> changed:

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


--- Comment #9 from Kenji Hara <k.hara.pg at gmail.com> 2013-07-08 21:52:32 PDT ---
The old behavior was wrong-code bug, and fixed in 2.061.

Introduced commit/codeline:
https://github.com/D-Programming-Language/dmd/commit/9553d0c66337b477375cb77743defcdd79b8064d#L4L3995

AA indexing + assign syntax is a special form in D. If the acquired payload
from AA is _immediately_ set by assignment, it is treated as an insertion for
non-existing key and won't throw RangeError. Otherwise, AA indexing should be
always treated as a read of existing key - even if it is on Lvalue-context.

I'd like to show more specific example.

struct S { int value = 42; }

S[string] myValues;

ref S getValue(string v) {
   return myValues[v];
}

void main() {
    import std.stdio;
    writeln(getValue("myValue").value); // what will be displayed?
}

In 2.060 and earlier, myValues[v] had returned a reference to *uninitialized*
memory. From 2.061, it correctly throws RangeError. That's @safe behavior.

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