Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seemingly unrelated closure changes type signature when using WKWebView.isInspectable #76171

Open
macdrevx opened this issue Aug 30, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@macdrevx
Copy link

Description

The following behavior seems like a bug in the swift compiler that ships with Xcode 16 beta 6.

Also filed as FB14783405

Hoping to see this fixed before Xcode 16 stable.

Reproduction

Add the following code snippet to a new iOS app project using Xcode 16 beta 6 and observe the error an warning called out in the comments within the itemProvider() method:

import WebKit

extension WKWebView {
    func allowInspectionForDebugBuilds() {
        // commenting out the following line makes it so that the completion closure argument of the trailing closure
        // passed to NSItemProvider.registerDataRepresentation(forTypeIdentifier:visibility:loadHandler:) is no longer
        // isolated to the main actor, thus resolving the build issues. It is unexpected that the presence or absence of
        // the following line would have this kind of impact.
        isInspectable = true
    }
}

class Foo {
    func itemProvider() -> NSItemProvider? {
        let itemProvider = NSItemProvider()
        itemProvider.registerDataRepresentation(forTypeIdentifier: "", visibility: .all) { completion in
            Task.detached {
                guard let url = URL(string: "") else {
                    completion(nil, NSError()) // error: Expression is 'async' but is not marked with 'await'
                    return
                }
                let task = URLSession.shared.dataTask(with: url) { data, _, error in
                    completion(data, error) // warning: Call to main actor-isolated parameter 'completion' in a synchronous nonisolated context; this is an error in the Swift 6 language mode
                }
                task.resume()
            }
            return Progress()
        }
        return itemProvider
    }
}

Now, comment out the line isInspectable = true and observe that the error and warning disappear.

Expected behavior

Using or not using WKWebView.isInspectible has no bearing on the type signature of a completion closure from NSItemProvider.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)

Additional information

No response

@macdrevx macdrevx added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant