swift_getOpaqueTypeMetadata crash

Is it possible to avoid this EXC_BAD_ACCESS on swift_getOpaqueTypeMetadata?

import SwiftUI
extension View {

    @available(iOS 14, *)
    @available(iOS, deprecated: 15)
    @ViewBuilder
    func interactiveDismissDisabled_14(_ isDisabled: Bool = true) -> some View {
        if #available(iOS 15, *) {
            interactiveDismissDisabled(isDisabled)
        } else {
            // Custom implementation of the above on older systems.
            firstUIResponder(of: UIViewController.self) {
                guard let vc = $0 else {
                    report()
                    return
                }
                vc.isModalInPresentation = isDisabled
            }
        }
    }
}

It crashes if I run this on iOS 14. Seems like the problem is in optimization since it doesn't crash if compiled with -Onone.
I would like to avoid wrapping result type into AnyView.

In the meanwhile I defined the method with @_optimise(none).

1 Like

I think this is worth reporting to bugs.swift.org, because optimisations shouldn’t change whether that code crashes or not. Seems like an optimiser bug to me.

I don’t really have any better temporary solution than the one you’re already using

@Stanislav_Smida Try with the Xcode 13.3 beta. There have been a number of weird, iOS 14 + release build only crashes reported on these forums, at least some of which are fixed in Xcode 13.3.

I ran into a very, very similar issue in __swift_instantiateConcreteTypeFromMangledName using SwiftUI + #available. This person also ran into one in swift::ResolveAsSymbolicReference::operator (which also appears to be related to demangling + SwiftUI + #available) and then there's this one which had something to do with concurrency.

Until you can actually build a release using Xcode 13.3, you can try this workaround from the above-linked developer forums thread. Something similar worked for me & this way you don't have to set @_optimize(none).

Thank you both. The issue is fixed in Xcode 13.3!