How to enforce Swift 5.8.1 compiler to require explicit existential `any` keyword?

I want to set a compiler flag to always emit warnings if I don't use any keyword on my existential types. I didn't find the flags in the official documentatin — the only thing I could find is the flag -enable-explicit-existential-types in apple/swift repo (PR #40282). But it doesn't seem to work

Also, I think I found a bug in Swift 5.8.1 compiler. If I set OTHER_SWIFT_FLAGS = "-enable-explicit-existential-types" , SWIFT_STRICT_CONCURRENCY = complete and use AppDelegate via main.swift, I get the following error:

error: Filename "main.swift" used twice: '/Users/admin/Documents/XcodeProjects/TestProjects/TestExistentialAny/TestExistentialAny/main.swift' and '-e' (in target 'TestExistentialAny' from project 'TestExistentialAny')
note: Filenames are used to distinguish private declarations with the same name (in target 'TestExistentialAny' from project 'TestExistentialAny')

I use Xcode 14.3.1 (14E300c)

Any help with this?

Answered by DTS Engineer in 761877022

Making any required is a feature that's going to be enforced in Swift 6, but that's still a way off in the future. SE-0362 introduced a way to opt in to such "future features", and the any requirement is listed as one such, under the identifier ExistentialAny. You'll need to pass this to the compiler in a -enable-upcoming-feature ExistentialAny compiler flag.

Regarding main.swift, it sounds like you've manually created a main.swift and you're also using the @main construct from whichever app lifecycle template you chose when creating the project. Those will conflict.

If you're using the SwiftUI lifecycle, you should use @UIApplicationDelegateAdaptor to get an app delegate. If not, use @main in the app delegate class declaration instead. Either way, you don't need to (and shouldn't) create a main.swift file.

Filed a bug via Feedback Assistant (FB12960674)

Accepted Answer

Making any required is a feature that's going to be enforced in Swift 6, but that's still a way off in the future. SE-0362 introduced a way to opt in to such "future features", and the any requirement is listed as one such, under the identifier ExistentialAny. You'll need to pass this to the compiler in a -enable-upcoming-feature ExistentialAny compiler flag.

Regarding main.swift, it sounds like you've manually created a main.swift and you're also using the @main construct from whichever app lifecycle template you chose when creating the project. Those will conflict.

If you're using the SwiftUI lifecycle, you should use @UIApplicationDelegateAdaptor to get an app delegate. If not, use @main in the app delegate class declaration instead. Either way, you don't need to (and shouldn't) create a main.swift file.

How to enforce Swift 5.8.1 compiler to require explicit existential `any` keyword?
 
 
Q