Thread overview | |||||
---|---|---|---|---|---|
|
July 21, 2015 [Issue 12491] [AA] Disallow non-`immutable` types as associative array keys | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12491 Martin Nowak <code@dawg.eu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |code@dawg.eu --- Comment #1 from Martin Nowak <code@dawg.eu> --- How about something less drastic, e.g. AA's only allow const access to their keys? > This will cause a massive code breakage when e.g. mutable classes are used as keys. That's almost the same as disallowing classes as keys. -- |
July 21, 2015 [Issue 12491] [AA] Disallow non-`immutable` types as associative array keys | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12491 Steven Schveighoffer <schveiguy@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |schveiguy@yahoo.com --- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> --- (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. -- |
December 17, 2022 [Issue 12491] [AA] Disallow non-`immutable` types as associative array keys | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12491 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P2 |P4 -- |
Copyright © 1999-2021 by the D Language Foundation