digitalmars.D.bugs - [Issue 3825] New: A bug-prone situation with AAs
- d-bugmail puremagic.com (33/33) Feb 18 2010 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (17/17) Feb 02 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (10/10) Feb 02 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (10/10) May 09 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (7/7) Jun 21 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (10/10) Oct 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (10/10) Jan 11 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (19/24) Jan 12 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (13/13) Mar 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (6/6) Mar 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (9/9) Mar 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3825
- d-bugmail puremagic.com (13/13) Mar 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=3825
http://d.puremagic.com/issues/show_bug.cgi?id=3825
Summary: A bug-prone situation with AAs
Product: D
Version: 2.040
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: druntime
AssignedTo: sean invisibleduck.org
ReportedBy: bearophile_hugs eml.cc
import std.stdio;
void main() {
string[] words = ["how", "are", "you", "are"];
int[string] aa1;
foreach (w; words)
aa1[w] = ((w in aa1) ? (aa1[w] + 1) : 2);
writeln(aa1); // Prints: [how:1,you:1,are:2]
int[string] aa2;
foreach (w; words)
if (w in aa2)
aa2[w]++;
else
aa2[w] = 2;
writeln(aa2); // Prints: [how:2,you:2,are:3]
}
This can be a source of bugs in programs. I don't know if there are ways to
help the programmer avoid this bug.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 18 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3825
yebblies <yebblies gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
CC| |yebblies gmail.com
Platform|x86 |All
Version|2.040 |D1 & D2
AssignedTo|nobody puremagic.com |yebblies gmail.com
Summary|A bug-prone situation with |AAs entries are default
|AAs |initialized before the new
| |value is evaluated
OS/Version|Windows |All
Severity|normal |major
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 02 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3825
yebblies <yebblies gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jmdavisProg gmx.com
*** Issue 5021 has been marked as a duplicate of this issue. ***
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 02 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3825
Jonathan M Davis <jmdavisProg gmx.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |luka8088 owave.net
PDT ---
*** Issue 8070 has been marked as a duplicate of this issue. ***
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 09 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3825 Yesterday I've wasted some hours to locate this problem again in one of my programs. I hope this bug will be fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 21 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3825
yebblies <yebblies gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dawg dawgfoto.de
*** Issue 7914 has been marked as a duplicate of this issue. ***
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 29 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3825
Kenji Hara <k.hara.pg gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |pull
https://github.com/D-Programming-Language/dmd/pull/1465
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3825 Hara, I am reading the discussions in Pull 1465, and I have to say I use this kind of code all the time: aa[x]++; It's very handy. It's similar to a Python defaultdict:defaultdict(<type 'int'>, {'a': 1}) If you disallow that If you disallow that, I will have tons of broken code. And I have to replace: aa[x]++; With: if (x in aa) aa[x]++; else a[x] = 0; This makes D code longer, and it doesn't make it safer. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------from collections import defaultdict d = defaultdict(int) x = 'c' d[x] += 1 d
Jan 12 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3825 Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d5aac8cc2bcc43e8753d889eff8e005f5c7443ce fix Issue 3825 - AAs entries are default initialized before the new value is evaluated https://github.com/D-Programming-Language/dmd/commit/4af794608d6a29a1b03216038bcab63658ea9d87 Issue 3825 - AAs entries are default initialized before the new value is evaluated -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3825 Woo, after more than three years now it seems to work correctly. Close? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3825
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3825
Walter Bright <bugzilla digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
CC| |bugzilla digitalmars.com
Version|D1 & D2 |D1
Resolution|FIXED |
19:49:22 PST ---
Fixed for D2 only. Reopened as a D1 bug.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 03 2013









d-bugmail puremagic.com 