D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6722 - Can't remove a char[] key from an AA with immutable(char)[] key type.
Summary: Can't remove a char[] key from an AA with immutable(char)[] key type.
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: bootcamp, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-09-23 20:58 UTC by siegelords_abode
Modified: 2024-12-13 17:56 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description siegelords_abode 2011-09-23 20:58:23 UTC
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?
Comment 1 Jonathan M Davis 2011-09-23 21:15:55 UTC
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.
Comment 2 Stewart Gordon 2012-02-12 12:35:58 UTC
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.

(In reply to comment #1)
> 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.
Comment 3 dlangBugzillaToGithub 2024-12-13 17:56:30 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18371

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB