Numberick icon indicating copy to clipboard operation
Numberick copied to clipboard

Conditionally compiled availability annotations?

Open oscbyspro opened this issue 2 years ago • 3 comments

I tried to set up a GitHub workflow with tests on Linux (#60) (#63), but I discovered that the Swift 5.7 compiler is ~~broken~~. In particular, it cannot parse the following in some situations. It works on Swift 5.8, and on Xcode 14.2 after I pushed a hot-fix, but it still fails on Swift 5.7 using Linux.

#if SBI && swift(>=5.8)
@available(iOS 16.4, macCatalyst 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4, *)
#endif

The supposed problem is that @available expects a declaration, which is provided below #endif.


Edit: It seems like this is a Swift 5.8 feature (SE-0367). If so, then why does it compile on Xcode 14.2?

oscbyspro avatar Aug 19 '23 06:08 oscbyspro

You can try it like this:

#if SBI && swift(>=5.8)
@available(iOS 16.4, macCatalyst 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4, *)
extension NBKDoubleWidth {
#else
extension NBKDoubleWidth {
#endif

ypopovych avatar Aug 19 '23 09:08 ypopovych

Sadly extension NBKDoubleWidth { does not count as a declaration:

#if SBI && swift(>=5.8)
@available(iOS 16.4, macCatalyst 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4, *)
extension NBKDoubleWidth {
#else
extension NBKDoubleWidth {
#endif // 🛑 Expected '}' at end of extension 🛑 Expected declaration
}      // 🛑 Extraneous '}' at top level

oscbyspro avatar Aug 19 '23 10:08 oscbyspro

Arghhh. They should rewrite the compiler into Swift and redo the parser and macro preprocessor. Too many bugs. When you do a lot of metaprogramming it starts to crash on proper code. Had a couple of type workarounds in my libs because the compiler crashes non-stop.

ypopovych avatar Aug 19 '23 10:08 ypopovych