Possible misdiagnosis of SE-0054?

I'm writing some code that makes use of the type of an ImplicitlyUwrappedOptional, like so:

let signature = (@convention(c) () -> Void)!.self

(I'm using dlsym; so I need to perform an unsafeBitCast with this later)

In the latest beta of Xcode, I'm getting the warning "Using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead", which I understand is supposed to be for of SE-0054: Abolish ImplicitlyUnwrappedOptional type (specifically, from this pull request). However, I don't see how it applied to my case: I'm taking the type of an ImplicitlyUnwrappedOptional, not using it in a nested type. Interestingly, this gets away with no warnings:

let signature = ImplicitlyUnwrappedOptional<(@convention(c) () -> Void)>.self

Is there a bug here, or am I misunderstand this (if so, could someone explain what's wrong with it)?

ImplicitlyUnwrappedOptional isn't going to be a type at all anymore. We put the warnings specifically around the use of ! because that's easier to detect, but yes, using it in any position that isn't the top-level type of a variable, parameter, or return value is deprecated and will be removed. (@rudkx has already done a lot of work to actually do that removing in Swift 5, some of which will start showing up even in Swift 4.1.)

Ahh, I see; thanks for the clarification. I guess in this case I should be able to use (@convention(c) () -> Void)?.self and it'll be mapped to an "ImplicitlyUnwrappedOptional" property (as in, a top-level one declared as a variable with a ! at the end).

1 Like