[SR-13760] Existing calls to ObjC methods are unexpectedly 'async' #56157
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
concurrency
Feature: umbrella label for concurrency language features
Attachment: Download
Environment
MacOS 11 SDK, Xcode 12.2 Beta 3
Additional Detail from JIRA
md5: 25b07271a8912c747ceea50b3a43c7e7
Issue Description:
We get an unexpected error in the following code,
at the synchronous call to NSWindow's
beginSheet(_:completionHandler: )
method. The error states'async' in a function that does not support concurrency
.According to the XCode Jump-to-Definition, the Swift declaration is:
I believe the 'async-looking' rule should be kicking in for this ObjC method to import two versions of the method (both async and sync) because of its declaration in
NSWindow
, which according toNSWindow.h
for MacOS 11 SDK from XCode 12.2 beta 3 is:But, attempting to duplicate this declaration in a separate ObjC class called from Swift does not trigger the bug:
The difference here is that Swift type synthesized from the declaration of
MyNSWindow:myBeginSheet:
says thatsheetWindow
is an {{NSWindow![](}}, not just an {{NSWindow}} as in {{NSWindow:myBeginSheet:}}, even though I just copied the method decl as-is from the header. The ) version of the type is what I would expect, because the nullability of the pointer is not specified. So, if you specify_Nonnull
onMyNSWindow:myBeginSheet:
'ssheetWindow
then the error will be triggered on this example.The next interesting aspect of this bug is that if you make a call to
NSWindow:beginSheet
from a subclass, that call-site is not considered an async call (nor is the method making that call):Things get a bit weirder when you vary the the combination of pointer's type and nullability specifier when crafting a reduced ObjC example that triggers this bug. Here's the complete reduced example demonstrating this:
Debugging Progress
First, to compare what's going on with the difference between
compareError
andok0
, I've dumped and trimmed the constraint solver output and attached them here. From what I gather, the most relevant difference is the order in which the overload choices are considered and how they are scored:Notice that the disjunction includes both async and sync versions, but in the case with
Request
, the first choice "attempted," which is the async one, ends up being the final choice; there doesn't seem to be any output indicating that it attempted the sync version in that case.The text was updated successfully, but these errors were encountered: