[Issue 9498] Rang violation using AA
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jun 29 22:34:59 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9498
--- Comment #5 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-06-29 22:34:57 PDT ---
(In reply to comment #4)
> This code works because indexing an AA with a key that does not exist is valid
> in an lvalue context:
>
> int[string] aa;
> aa["asd"] += 2;
>
> The following code also indexes an AA with a missing key in an lvalue context:
>
> int[string] aa;
> ref int get() { return aa["asd"]; }
> get() += 2;
>
> The assumption here is that indexing an AA with a non-existing key in a context
> where an lvalue is expected does not result in a range violation.
>
> Do you know of any reason why this is an incorrect assumption?
Actually D does not have notion of lvalue context - TDPL says about read and
write operations. According to it, returning from function is a read operation.
And function refness does not guarantee that original lvalue will be modified.
The use case could be:
int a = get();
which means refness is wiped out and operation is effectively a read operation.
Situation could be follows:
ref int foo() { return aa["asd"]; }
int bar() { return aa["asd"]; }
not only this is confusing and inconsistent, but it defeats the purpose of
having aaGetRvalueX - anyone who want allocation would be just putting ref to
function declaration to make things works.
--
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