Help improve error message

H. S. Teoh hsteoh at qfbox.info
Tue May 9 01:13:32 UTC 2023


On Mon, May 08, 2023 at 10:12:53PM +0000, Petar via Digitalmars-d wrote:
[...]
> > Two problems. One is straightforward, but requires some language
> > updates: Having some mechanism to tell `opIndex` that the result
> > should be inserted if it doesn't exist. Used in cases like:
> > ```d
> > int[int][int] aa;
> > 
> > ++aa[42][24]; // currently compiles
> > ```
> 
> On Monday, 8 May 2023 at 16:08:32 UTC, Steven Schveighoffer wrote:
> Yeah, the so-called
> [autovivification](https://en.wikipedia.org/wiki/Autovivification).
> For a moment I was confused as to what's the problem with simply:
> 1. Having `opIndex` return by `ref`, so you can mutate the value
> in-place.
> 2. Having `opIndex` construct the value on first access, something
> along the lines of:
>   `if (key !in impl) return impl.at(key).emplace!Value();`
> 
> But then I remembered that `aa[missingKey]` actually throws a
> `RangeError` and we wouldn't be able to replicate the behaviour if we
> did 2.

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


T

-- 
Democracy: The triumph of popularity over principle. -- C.Bond


More information about the Digitalmars-d mailing list