mirror of
https://github.com/apple/swift-atomics
synced 2026-11-24 04:27:48 +00:00
Swift 5.6/7 generates new compiler warnings when non-final classes
conform to `AtomicReference`. The warnings are pointing out a real
design issue: Self is covariant in protocols, but we intend atomic
operations to always deal with the base class rather than individual
subclasses.
Add a new associated type requirement to AtomicValue to represent the
actual type that originally conformed to the protocol, and add
explicit same-type requirements to clients to ensure they aren’t
asked to return a subclass.
Unfortunately, this change is source breaking:
```
class Base: AtomicReference {}
class Derived: Base {}
let ref = ManagedAtomic<Derived?>(nil)
// before: OK
// after: 'ManagedAtomic' requires the types 'Derived' and 'Base' be equivalent
```