https://issues.dlang.org/show_bug.cgi?id=12491

Steven Schveighoffer <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #2 from Steven Schveighoffer <[email protected]> ---
(In reply to Martin Nowak from comment #1)
> How about something less drastic, e.g. AA's only allow const access to their
> keys?

That doesn't help. Const access doesn't mean nobody has mutable access.

Consider that the most common source of an error here is not that someone gets
the key from the AA, but rather that he has a mutable pointer to the key from
another source that he doesn't realize will affect the AA.

I personally think AAs simply shouldn't enforce any immutability. Enforcing
const is useless, and enforcing immutable makes keys that aren't written with
immutability in mind unusable. The result is, if you use a mutable key type for
an AA, don't change any of the keys, or the AA doesn't work any more (note that
this won't cause corruption, just leakage, so it can still be @safe).

In addition, immutability of the *entire* key isn't necessary. You could have
members that are mutable but don't affect the hash/equal calculation. It would
be impossible for the compiler to enforce this. I'd rather just leave it up to
the user.

--

Reply via email to