digitalmars.D.bugs - [Issue 238] New: Cannot initialise const field from foreach loop on associative array
- d-bugmail puremagic.com (38/38) Jul 03 2006 http://d.puremagic.com/issues/show_bug.cgi?id=238
- d-bugmail puremagic.com (9/9) Dec 24 2006 http://d.puremagic.com/issues/show_bug.cgi?id=238
- d-bugmail puremagic.com (4/4) Dec 26 2006 http://d.puremagic.com/issues/show_bug.cgi?id=238
http://d.puremagic.com/issues/show_bug.cgi?id=238 Summary: Cannot initialise const field from foreach loop on associative array Product: D Version: 0.162 Platform: PC OS/Version: Windows Status: NEW Keywords: rejects-valid Severity: minor Priority: P3 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: deewiant gmail.com This is a bit confusing. The code explains it best: -- class Confectionary { this(int sugar) { //if (sugar < 500) // tastiness = 200; //for (int i = 0; i < 10; ++i) // tastiness = 300; //int[] tastinesses_array; //foreach (n; tastinesses_array) // tastiness = n; int[int] tastinesses_aa; foreach (n; tastinesses_aa) tastiness = n; } const int tastiness; } -- All the commented-out cases are acceptable ways of initialising the const member, tastiness. However, DMD issues an error "can only initialize const tastiness inside constructor" for the last foreach loop. This can be circumvented by putting the loop in a function which returns the value to be assigned to the field, but it's still an annoyance. --
Jul 03 2006
http://d.puremagic.com/issues/show_bug.cgi?id=238 deewiant gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED Fixed in DMD 0.178. --
Dec 24 2006
http://d.puremagic.com/issues/show_bug.cgi?id=238 Fixed DMD 0.178 --
Dec 26 2006