www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2173] New: foreach iteration not possible for associative array indexed with static array

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2173

           Summary: foreach iteration not possible for associative array
                    indexed with static array
           Product: D
           Version: 1.031
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: georg op-co.de


Trying to foreach through an AA[SA] generates a compiler error:

import std.stdio;
import std.md5;
int main(char[][] args) {
        int[ubyte[16]] md5count;
        foreach (md5, count; md5count)
                writefln("%s: %d", std.md5.digestToString(md5), count);
        return 0;
}

Both gdc and dmd bail out on the foreach statement with:
"test.d(5): Error: cannot have out or ref parameter of type ubyte[16u]"

Possible workarounds:
 * use a wrapper struct for the static array (looks ugly)
 * use foreach (md5; md5count.keys) ... count = md5count[md5]
      (decreases performance almost by 50%)


-- 
Jun 25 2008
next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2173


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch




------- Comment #1 from davidl 126.com  2008-06-26 01:39 -------
i bet the code actually meant as following:

mtype.c (2790):
            if (arg->storageClass & (STCout | STCref | STClazy))
            {
---             if (t->ty == Tsarray)
+++             if (t->ty != Tsarray)
                    error(loc, "cannot have out or ref parameter of type %s",
t->toChars());
            }

I hand-crafted a dmd which bypass this check, it can generate correct binary. 


-- 
Jun 25 2008
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<d-bugmail puremagic.com> wrote in message 
news:g3vdj3$114l$1 digitalmars.com...
 http://d.puremagic.com/issues/show_bug.cgi?id=2173

 i bet the code actually meant as following:

 mtype.c (2790):
            if (arg->storageClass & (STCout | STCref | STClazy))
            {
 ---             if (t->ty == Tsarray)
 +++             if (t->ty != Tsarray)
                    error(loc, "cannot have out or ref parameter of type 
 %s",
 t->toChars());
            }

Now static arrays are the only type that can be out, ref, or lazy. I don't think that's much of a fix. Maybe just get rid of the check entirely.
 I hand-crafted a dmd which bypass this check, it can generate correct 
 binary.

How can you do that? The backend is closed source.
Jun 26 2008
prev sibling next sibling parent "Koroskin Denis" <2korden gmail.com> writes:
On Thu, 26 Jun 2008 17:19:41 +0400, Jarrett Billingsley  
<kb3ctd2 yahoo.com> wrote:

 <d-bugmail puremagic.com> wrote in message
 news:g3vdj3$114l$1 digitalmars.com...
 http://d.puremagic.com/issues/show_bug.cgi?id=2173

 i bet the code actually meant as following:

 mtype.c (2790):
            if (arg->storageClass & (STCout | STCref | STClazy))
            {
 ---             if (t->ty == Tsarray)
 +++             if (t->ty != Tsarray)
                    error(loc, "cannot have out or ref parameter of type
 %s",
 t->toChars());
            }

Now static arrays are the only type that can be out, ref, or lazy. I don't think that's much of a fix. Maybe just get rid of the check entirely.
 I hand-crafted a dmd which bypass this check, it can generate correct
 binary.

How can you do that? The backend is closed source.

That's not hard to patch je to jne, I assume :)
Jun 27 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2173





------- Comment #2 from davidl 126.com  2008-07-02 09:12 -------
umm, the patch is incorrect.. 
bypassing the whole test should work.
/*
            if (arg->storageClass & (STCout | STCref | STClazy))
            {
                if (t->ty == Tsarray)
                if (t->ty != Tsarray)
                    error(loc, "cannot have out or ref parameter of type %s",
t->toChars());
            }
*/


-- 
Jul 02 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2173


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bearophile_hugs eml.cc
         Resolution|                            |WORKSFORME


--- Comment #3 from bearophile_hugs eml.cc 2010-02-18 11:09:11 PST ---
I think this bug is now fixed, because fixed-sized arrays are managed by value.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 18 2010