I had code like this:
func g<T>(_ v: consuming sending T) {}
func f<T: ExpressibleByNilLiteral>(_ type: T.Type = T.self) {
g(T(nilLiteral: ()))
}
Which no longer compiles under Swift 6.2:
error: sending value of non-Sendable type 'T' risks causing data races [#SendingRisksDataRace]
| `- note: Passing task-isolated value of non-Sendable type 'T' as a 'sending' parameter to global function 'g' risks causing races inbetween task-isolated uses and uses reachable from 'g'
(note that this doesn't mention how the heck that can occur; I believe the text of this warning is a complete red herring?)
I can fix it by adding a : SendableMetatype
constraint:
func g<T>(_ v: consuming sending T) {}
func f<T: ExpressibleByNilLiteral & SendableMetatype>(_ type: T.Type = T.self) {
g(T(nilLiteral: ()))
}
I'm not even sure why this happens. Maybe the compiler thinks there could be protocol requirements in ExpressibleByNilLiteral
beyond the constructor? But isn't it safe to send a value even if it has global-actor-isolated conformances, so long as you're not sending it as that conformance? And shouldn't the constructor always be assumed to return an isolated instance?
@Douglas_Gregor, @Michael_Gottesman is this a bug?