www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 238] New: Cannot initialise const field from foreach loop on associative array

reply d-bugmail puremagic.com writes:
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=238


deewiant gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from deewiant gmail.com  2006-12-24 03:45 -------
Fixed in DMD 0.178.


-- 
Dec 24 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=238





------- Comment #2 from bugzilla digitalmars.com  2006-12-27 01:58 -------
Fixed DMD 0.178


-- 
Dec 26 2006