Type system loses track of a Sendable type's conformance?

I’m struggling with an apparent conflict in warning messages emitted by the compiler which appears unable to make up its mind on whether Notification is Sendable:

Non-Sendable type 'NotificationCenter.Notifications.Element?' (aka 'Optional<Notification>') of nonisolated property 'first' cannot be sent to main actor-isolated context; this is an error in the Swift 6 language mode

and

Conformance of 'Notification' to 'Sendable' is unavailable in iOS; this is an error in the Swift 6 language mode

vs:

Conformance of 'Notification' to protocol 'Sendable' was already stated in the type's module 'Foundation'

Both messages do not appear in the same codebase. Some context:


When I am using Notification in an asynchronous context, I receive the former warning, for instance:

extension AsyncSequence {
    public var first: Element? {
        get async throws {
            var it = self.makeAsyncIterator()
            return try await it.next()
        }
    }
}

// Non-Sendable type 'NotificationCenter.Notifications.Element?' (aka 'Optional<Notification>') of nonisolated property 'first' cannot be sent to main actor-isolated context; this is an error in the Swift 6 language mode
_ = try? await NotificationCenter.default.notifications(named: UIApplication.didBecomeActiveNotification).first

Interestingly, though, it appears the message is only triggered when we apply the extension function, e.g. the following is considered fine:

_ = await NotificationCenter.default.notifications(named: UIApplication.didBecomeActiveNotification).makeAsyncIterator().next()

The issue is not related to the optional wrapper type. We also encounter this situation (different message) e.g. with:

import AsyncAlgorithms

for await notification in
    merge( // Conformance of 'Notification' to 'Sendable' is unavailable in iOS; this is an error in the Swift 6 language mode
        NotificationCenter.default.notifications(named: UIApplication.backgroundRefreshStatusDidChangeNotification),
        NotificationCenter.default.notifications(named: UIApplication.backgroundRefreshStatusDidChangeNotification)
    ) {
        print("\(notification.name.rawValue)")
}

but we don’t get the message for:

for await notification in
    NotificationCenter.default.notifications(named: UIApplication.backgroundRefreshStatusDidChangeNotification) {
    print("\(notification.name.rawValue)")
}

Regardless, the warning messages would imply that our Notification type is not Sendable. That might explain it (though it wouldn’t explain why the message goes away for the simpler cases) — but we again receive conflicting information if we try to make it Sendable:

// Conformance of 'Notification' to protocol 'Sendable' was already stated in the type's module 'Foundation'
extension Notification: @unchecked @retroactive Sendable {}

Though, worth noting that this extension does resolve the warning messages in the problematic cases above.

The compiler tells us Sendable conformance is declared in Foundation:

Foundation.Notification:6:11: note: 'Notification' declares conformance to protocol 'Sendable' here
extension Notification : Sendable {

Though unhelpfully I am unable to navigate here to find out what it looks like. It seems like some kind of stub.

What is actually going on? AFAIK Notification IS in fact declared to be Sendable but somehow this conformance is lost to the type system once we access the AsyncSequence through helper functions. Kindly advise.

Just a guess: maybe you're missing some “import Foundation”?