8 ms·
https://go.dev/play/p/xolc9oPwA0C https://go.dev/play/p/xolc9oPwA0C Interfaces don't have a zero type, which means that we can't have an atomic.Value which sto
by bumper_crop 4y ago
https://go.dev/play/p/xolc9oPwA0C https://go.dev/play/p/xolc9oPwA0C
Interfaces don't have a zero type, which means that we can't have an atomic.Value which stores Shape. Atomic Value would be much easier to reason about if it had store semantics similar to a regular `var foo Shape = ...`. One of the other comment threads talked about generics helping this, so maybe there is hope.
- deleted 4y ago[deleted]
- yencabulator 4y agoParent means var bestShape atomic.Value bestShape.Store((*Circle)(nil))
- morelisp 4y agoWhich will store it as a *Circle, and only allow more *Circles, not Shapes. That part of GP’s claim is correct. It just had nothing to do with atomicity; it means something specific, not just “I like the failure mode.”
- yencabulator 4y agoThat's pretty easy to workaround: type shapeContainer struct { Shape } The usual way to use atomic.Value is by writing strongly-typed wrappers anyway, so that doesn't affect your codebase beyond about 3 lines.