Warn in future Swift versions

I have a lot of code that I wish to change once Conditional Conformances and auto synthesis of Equatable and Hashable is finally released.

Is it possible for me to insert a warning in the code that will be emitted once a specific version of Swift is used to compile?

(I know that I can easily add a comment that I can easily search for - just curious if the above is at all possible).

1 Like

I am not sure if something like that is possible, but if you want compile-time warning that will show up in certain versions, you could do something like this:

#if swift(>=5.0)
    var x = 1
#endif

Assuming Conditional Conformances will be part of swift 5.0.
Warning will be unrelated to what you actually want to achieve, but it will point you to the code where you want to change something once feature is unlocked. You can also add comment explaining what is going on but that, obviously, won't be part of the warning

1 Like

I think what you want is SE-0196, which is accepted but not implemented.

1 Like

It's implemented in Implement #warning and #error by harlanhaskins · Pull Request #14048 · apple/swift · GitHub, but won't be usable until Swift 5.0, reading the comments on that PR.

1 Like