www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6722] New: Can't remove a char[] key from an AA with immutable(char)[] key type.

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

           Summary: Can't remove a char[] key from an AA with
                    immutable(char)[] key type.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: siegelords_abode yahoo.com



int[char[]] a;
int[immutable(char)[]] b;

char[] s;

int v1 = a[s]; // Fine
int v2 = b[s]; // Fine
a.remove(s); // Fine
b.remove(s); // Error: cannot implicitly convert expression (s) of type char[]
to string

Can we be done with the compiler magic for the AA's?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 23 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6722


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
The simplest solution is to just make it so that it's illegal to declare an AA
with a key which isn't either a value type or immutable and make it so that
_all_ functions or operators which take the key must take a type which is
implicitly convertible to the key type (including its immutability). It _would_
break a fair bit of code though, I suspect. Still, it would be a fairly simple
change to make in any code that it breaks, and it could be grandfathered in by
making it a warning first.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 23 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6722


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |smjg iname.com
           Platform|Other                       |All
         OS/Version|Linux                       |All



A char[] can be safely compared with an immutable(char)[], so the code should
be valid.

Putting a value into an AA is another matter though.


 The simplest solution is to just make it so that it's illegal to 
 declare an AA with a key which isn't either a value type or 
 immutable
Agreed.
 and make it so that _all_ functions or operators which take the key 
 must take a type which is implicitly convertible to the key type 
 (including its immutability).
For functions that put data into an AA, yes. For lookup functions (retrieval and removal), it should be sufficient that it's a type that is implicitly convertible to the const version of the key type. (Just having an == operator with the key type isn't sufficient, as it needs to check the hash first.) For foreach, the only requirement should be that the key variable is of a type to which the key type can be implicitly converted. But this is a distinct matter from this bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 12 2012