Bug 22237 – AA.update is underspecified

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-24T20:02:51Z
Last change time
2022-08-01T13:40:48Z
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2021-08-24T20:02:51Z
The spec gives this signature for .update on associative arrays: > .update(Key key, Value delegate() create, Value delegate(Value) update) https://dlang.org/spec/hash-map.html#properties But the actual implementation in druntime also allows returning void: ``` void main() { int[int] aa; aa.update(3, () => 3, (int x) {}); } ``` The idea being that the delegate can take the existing value by `ref` and update that way as well. This is how the update function is described: > The update function provides a means to construct a new value via the > create delegate or update an existing value via the update delegate. > Looks up key; if it exists applies the update delegate else evaluates > the create delegate and adds it to the associative array This doesn't specify how the update delegate is actually applied, and whether you need to modify with ref, return a new value, or both.
Comment #1 by dlang-bot — 2022-08-01T12:46:57Z
dlang/dlang.org pull request #3360 "Fix Issue 22237 - AA.update is underspecified" was merged into master: - 2779bf1a92180fc741b203982b799c864bdfde3c by Nick Treleaven: Fix Issue 22237 - AA.update is underspecified Make example runnable. Update example to match part of https://github.com/dlang/dlang.org/pull/3358. Add link to object.update. https://github.com/dlang/dlang.org/pull/3360
Comment #2 by nick — 2022-08-01T13:40:48Z
Typo in my commit: > https://github.com/dlang/dlang.org/pull/3358. should actually be: https://github.com/dlang/dmd/pull/14335 which updated object.d.