Thread overview | |||||
---|---|---|---|---|---|
|
October 09, 2010 [Issue 5021] New: Associative array assigned to in spite of exception | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=5021 Summary: Associative array assigned to in spite of exception Product: D Version: unspecified Platform: Other OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: jmdavisProg@gmx.com --- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-10-09 00:49:21 PDT --- This program: import std.string; int func() { throw new Exception("It's an exception."); } void main() { int[string] arr; try { arr["hello"] = func(); } catch(Exception e) { } assert(arr.length == 0, format("actual: %s", arr.length)); } results in this output: core.exception.AssertError@d.d(20): actual: 1 ---------------- ./d(_d_assert_msg+0x18) [0x8081ab8] ./d(_Dmain+0x8f) [0x807eb0f] ./d(extern (C) int rt.dmain2.main(int, char**)) [0x8081ca6] ./d(extern (C) int rt.dmain2.main(int, char**)) [0x8081c00] ./d(extern (C) int rt.dmain2.main(int, char**)) [0x8081cea] ./d(extern (C) int rt.dmain2.main(int, char**)) [0x8081c00] ./d(main+0x96) [0x8081ba6] /usr/lib32/libc.so.6(__libc_start_main+0xe6) [0xf75f1c76] ./d() [0x807e9a1] The associative array should have been unchanged. The assignment never took place because an exception was thrown before the function could return the value to be assigned to the associative array. Since no assignment took place, the associative array should not have changed, but it did. It has 1 value in it where it should have 0. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 12, 2011 [Issue 5021] Associative array assigned to in spite of exception | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | http://d.puremagic.com/issues/show_bug.cgi?id=5021 Jonathan M Davis <jmdavisProg@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |major --- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-08-12 01:26:13 PDT --- Okay. I just spent a few hours trying to track down a failure due to this, so I'm bumping it up to major (what the exact criteria for what level a bug is, I don't know, but this one is definitely annoying). What seems to be happening here is that the associative array gets assigned a default-initialized value if an exception was thrown from the expression on the right-hand side of the assignment. My best guess is that a default-initialized element is added to the AA as part of arr["hello"], and then when the assignment doesn't happen due to the exception, the AA is left with the default-initialized value in it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 03, 2012 [Issue 5021] Associative array assigned to in spite of exception | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | http://d.puremagic.com/issues/show_bug.cgi?id=5021 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |yebblies@gmail.com Resolution| |DUPLICATE --- Comment #2 from yebblies <yebblies@gmail.com> 2012-02-03 18:35:00 EST --- Same cause, same fix. *** This issue has been marked as a duplicate of issue 3825 *** -- 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