June 30, 2013 [Issue 9498] Rang violation using AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim Volckmann | http://d.puremagic.com/issues/show_bug.cgi?id=9498 --- Comment #8 from yebblies <yebblies@gmail.com> 2013-06-30 16:49:40 EST --- (In reply to comment #7) > Than you should read again if you don't see the relevance. Function returning AA value as discussed here is a case which should throw according to TDPL (spec is silent unfortunately) and current D implementation in case of non-ref functions. Presence of ref attribute does not matter because function performs read operation in the first place. How value is returned (by ref or not) is of secondary importance. TDPL is not an authoritative specification, so the fact this is in line with the way TDPL presents AAs does not conclusively prove this is correct behavior. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 09, 2013 [Issue 9498] Range violation using AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim Volckmann | http://d.puremagic.com/issues/show_bug.cgi?id=9498 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution| |INVALID --- Comment #9 from Kenji Hara <k.hara.pg@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: ------- |
Copyright © 1999-2021 by the D Language Foundation