My code suddenly started crashing in runtime and failing at compile time after upgrading to Swift 6.3 from 6.2

I know that it is not sudden, sorry for the clickbait title, but I couldn't describe it in another way. I found some changes in the compiler related to unions back in September, but I still do not know what to do.

Firstly, I got a compile-time failure: '__Anonymous_field0' is unavailable: refer to the members of the anonymous type instead, meanwhile all other platforms (Darwin, Glibc, Musl) were still able to compile fine without any changes.

public extension sigaction {
#if canImport(Darwin)
    typealias Union = __sigaction_u
#elseif canImport(Glibc)
    typealias Union = __Unnamed_union___sigaction_handler
#elseif canImport(Musl)
    typealias Union = __Unnamed_union___sa_handler
#elseif canImport(Bionic) && _pointerBitWidth(_32)
    typealias Union = __Unnamed_union___Anonymous_field0
#else
    typealias Union = __Unnamed_union___Anonymous_field1
#endif

    var handler: Union {
        get {
#if canImport(Darwin)
            __sigaction_u
#elseif canImport(Glibc)
            __sigaction_handler
#elseif canImport(Musl)
            __sa_handler
#elseif canImport(Bionic) && _pointerBitWidth(_32)
            __Anonymous_field0
#elseif canImport(Bionic)
            __Anonymous_field1
#endif
        }
        set {
#if canImport(Darwin)
            __sigaction_u = newValue
#elseif canImport(Glibc)
            __sigaction_handler = newValue
#elseif canImport(Musl)
            __sa_handler = newValue
#elseif canImport(Bionic) && _pointerBitWidth(_32)
            __Anonymous_field0 = newValue
#elseif canImport(Bionic)
            __Anonymous_field1 = newValue
#endif
        }
    }
}

Secondly, I commented out all the code that failed during compilation and got a crash while trying to understand what had even gone wrong. I tried to print the sigaction structure and got a runtime crash this time:

let structure = sigaction()
String(describing: structure) //crash
Mirror(reflecting: structure) //crash
1 Like

Tried to exclude this piece of code with:

#if !(compiler(>=6.3) && os(Android))
        print("6.2")
//code that fails
#else
        print("6.3")
#endif

but Swift 6.3 compiler still tries to compile code from the first scope and fails

That would be expected if you weren't compiling for Android. You'll need to describe what you're trying to do in more detail to get help. At the least, what platform are you using, what platform are you building for, and what version of the compiler are you using?